python - Selenium does not locate element -
i newbie python. have written code automatically login website, https://www.quora.com. issue is, selenium loads firefox perfectly, program not proceed further. is, not go on enter email , password.
from selenium import webdriver selenium.webdriver.common.keys import keys browser = webdriver.firefox() browser.get('https://www.quora.com') browser.implicitly_wait(30) email = browser.find_element_by_class_name('email') pw = browser.find_element_by_class_name('password') email.send_keys('my_email') pw.send_keys('my_password') pw.send_keys(keys.enter)
i have written similar program automate login gmail, works perfectly. code given below, although same above.
from selenium import webdriver selenium.webdriver.common.keys import keys browser = webdriver.firefox() browser.get('https://www.gmail.com') browser.implicitly_wait(10) email = browser.find_element_by_id('email') email.send_keys('my_username') email.send_keys(keys.enter) pw = browser.find_element_by_id('passwd') pw.send_keys('my_password') pw.send_keys(keys.enter)
both programs use implicit wait method, is, program waits specified time interval page load, followed throws exception.
i have tried explicit wait method, mentioned in selenium documentation http://selenium-python.readthedocs.org/waits.html. gmail login works method too, quora login not.
why happen? , how resolve it?
although shubham jain's answer ok, quora changes id's , classes often. notoriously hard scrape or with. design.
so if plan on doing scraping on quora(i advise against terms of service), best never use classes or id's targeting on webpage!
if try , search things not change tried do! close!
instead of:
email = browser.find_element_by_class_name('email')
do
email = browser.find_element_by_name('email')
you'll notice looking "class_name" , wanted "name".
same thing password!
pw = browser.find_element_by_class_name('password')
do
pw = browser.find_element_by_name('password')
sometimes these naming conventions can confusing, highly recommend getting @ searching xpath.
Comments
Post a Comment