I was making a simple program which enables me to fill out the login form and send email to someone.. and while i'm on it, it just don't go more and stopped at opening some link.
# Practice Program!
import requests, os, bs4, webbrowser
from selenium import webdriver
url = 'http://google.com'
res = requests.get(url)
res.raise_for_status()
browser = webdriver.Firefox()
browser.get(url)
signinElem = browser.find_element_by_id('gb_70')
signinElem.click()
idElem = browser.find_element_by_id('Email')
idElem.send_keys('not_my_real_id')
idElem.submit()
pwElem = browser.find_element_by_id('Passwd')
pwElem.send_keys('not_my_pw')
pwElem.submit()
mailElem = browser.find_element_by_class_name('gb_P')
mailElem.click()
composeElem = browser.find_element_by_class_name('class="T-I J-J5-Ji T-I-KE L3')
composeElem.click()
The code worked well until it hit pwElem
, which makes me wonder why signinElem
and idElem
worked but not pwElem
??
I happened to stuck with similar situation, where i can pass through some links, but others not. What is wrong with this code?
And i got following Error
Traceback (most recent call last): File "C:/Users/Cyber/Downloads/WriteMail.py", line 22, in pwElem = browser.find_element_by_id('Passwd') File "C:\Users\Cyber\Downloads\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 269, in find_element_by_id return self.find_element(by=By.ID, value=id_) File "C:\Users\Cyber\Downloads\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element 'value': value})['value'] File "C:\Users\Cyber\Downloads\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute self.error_handler.check_response(response) File "C:\Users\Cyber\Downloads\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"id","selector":"Passwd"} Stacktrace: at (file:///C:/Users/Cyber/AppData/Local/Temp/tmpczr__hhf/extensions/[email protected]/components/driver-component.js:10770) at (file:///C:/Users/Cyber/AppData/Local/Temp/tmpczr__hhf/extensions/[email protected]/components/driver-component.js:10779) at (file:///C:/Users/Cyber/AppData/Local/Temp/tmpczr__hhf/extensions/[email protected]/components/command-processor.js:12661) at (file:///C:/Users/Cyber/AppData/Local/Temp/tmpczr__hhf/extensions/[email protected]/components/command-processor.js:12666) at (file:///C:/Users/Cyber/AppData/Local/Temp/tmpczr__hhf/extensions/[email protected]/components/command-processor.js:12608)
HTML
for same\ – AnderssonHTML
with your browser? Right click on target element -> Show source – Andersson