it's login is fine, but i am not able to track the issue, here the code below
import xlrd, xlwt
USER_AGENT = 'Chrome'
SCRIPT = "var inputs = document.getElementsByTagName('input');"
"for(var i = 0; i < inputs.length; i++) {if(inputs[i].type.toLowerCase() == 'file')"
"{inputs[i].style.visibility = 'visible';inputs[i].style.display = 'inline !important';"
"inputs[i].style.opacity = 1;inputs[i].className = '';}}"
PIC_DIR = os.path.dirname(__file__)
XLS_TITLES = ('User','Password','proxyIP:portPort','Real Name','Username','Website','Bio')
def load_settings():
settings = []
rb = xlrd.open_workbook(os.path.dirname(__file__)+'./for_automation_testing.xlsx', formatting_info=False)
sheet = rb.sheet_by_index(0)
lines = [sheet.row_values(rownum) for rownum in range(1, sheet.nrows)]
for line in lines:
profile = {}
profile['user'] = line[0]
profile['pswd'] = line[1]
profile['proxy'] = line[2]
profile['name'] = line[3]
profile['username'] = line[4]
profile['website'] = line[5]
profile['bio'] = line[6]
settings.append(profile)
return settings
def writeline(ws, line_index, line):
count = 0
for cell in line:
ws.write(line_index, count, cell)
count += 1
def change_settings():
rb = xlrd.open_workbook('./for_automation_testing.xlsx', formatting_info=False)
sheet = rb.sheet_by_index(0)
rb_lines = [sheet.row_values(rownum) for rownum in range(1,sheet.nrows)]
wb = xlwt.Workbook()
ws=wb.add_sheet('sheet1')
count = 0
for line in rb_lines:
if count != 0 and line[4]:
line[0]=line[4]
writeline(ws, count, line)
count += 1
wb.save(os.path.dirname(__file__)+'/for_automation_testing.xlsx')
def path_to_random_pic():
list = []
for file in os.listdir(PIC_DIR):
if file.endswith(".jpg"):
list.append(PIC_DIR+'/'+file)
return random.choice(list)
def Main():
settings = load_settings()
for profile in settings:
ff_profile = webdriver.FirefoxProfile()
ff_profile.set_preference("general.useragent.override", USER_AGENT)
if profile['proxy']:
ff_profile.set_preference("network.proxy.type", 1)
ff_profile.set_preference("network.proxy.http", profile['proxy'].split(':')[0])
ff_profile.set_preference("network.proxy.http_port", int(profile['proxy'].split(':')[1]))
browser = webdriver.Firefox(ff_profile)
print("user {0} with proxy {1} running n".format(profile['user'], profile['proxy']))
browser.get('http://whatismyip.org/')
time.sleep(5)
start_mail_check = False
while True:
browser.get('https://www.instagram.com/accounts/login/?force_classic_login')
wait = WebDriverWait(browser, 10)
username = browser.find_element_by_id('id_username')
username.send_keys(profile['user'])
wait = WebDriverWait(browser, 2)
password = browser.find_element_by_id('id_password')
password.send_keys(profile['pswd'])
time.sleep(random.uniform(3.0, 4.0))
password.submit()
wait = WebDriverWait(browser, 10)
el = browser.find_elements_by_xpath('html/body/div/section/div/p')
if el:
if el[0].text == "Verify Your Account" or el[0].text == "Enter Security Code" or el[0].text == "Thanks":
print ' mail check!'
time.sleep(random.uniform(30.0, 60.0))
else:
break
while True:
time.sleep(10)
browser.get("https://www.instagram.com/accounts/edit/?wo=1")
I am getting this error when i ran project.py
Superuser$ python project.py
user diabruxaneas1989 with proxy 192.126.184.130:8800 running
Traceback (most recent call last):
File "project.py", line 158, in <module>
Main()
File "project.py", line 94, in Main
username = browser.find_element_by_id('id_username')
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 269, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 745, in find_element
{'using': by, 'value': value})['value']
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"id","selector":"id_username"}
Stacktrace:
at FirefoxDriver.prototype.findElementInternal_ (file:///var/folders/rc/vx_d14f14p97l02f35j6_dvw0000gn/T/tmp6I93xt/extensions/fxdriver@googlecode.com/components/driver-component.js:10770)
at FirefoxDriver.prototype.findElement (file:///var/folders/rc/vx_d14f14p97l02f35j6_dvw0000gn/T/tmp6I93xt/extensions/fxdriver@googlecode.com/components/driver-component.js:10779)
at DelayedCommand.prototype.executeInternal_/h (file:///var/folders/rc/vx_d14f14p97l02f35j6_dvw0000gn/T/tmp6I93xt/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///var/folders/rc/vx_d14f14p97l02f35j6_dvw0000gn/T/tmp6I93xt/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///var/folders/rc/vx_d14f14p97l02f35j6_dvw0000gn/T/tmp6I93xt/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)
I tried other solutions as well but still same error .
Any help would be appreciated, Thanks
Aucun commentaire:
Enregistrer un commentaire