首页 > 代码库 > Python+selenium 遇到的问题
Python+selenium 遇到的问题
最终写出来的代码:
from selenium import webdriver
driver = webdriver.Chrome("E:\chromedriver_win32\chromedriver.exe")
driver.get("https://test.tembin.com/oldriver/login")
driver.find_element_by_id("username").clear()
driver.find_element_by_id("username").send_keys("XXXX")
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys("XXX")
driver.find_element_by_xpath(".//*[@id=‘loginForm‘]/input").click()
driver.quit()
解决的问题:
Q1:
driver.find_element_by_xpath(".//*[@id=‘loginForm‘]/input").click()
定位的问题;用火狐浏览器定位
未解决的问题:
from selenium import webdriver
driver = webdriver.Chrome("E:\chromedriver_win32\chromedriver.exe")
driver.get("https://test.tembin.com/oldriver/login")
driver.find_element_by_id("username").clear()
driver.find_element_by_id("username").send_keys("15682776058")
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys("000000")
driver.find_element_by_xpath(".//*[@id=‘loginForm‘]/input").click()
driver.find_element_by_id("go").submit()
driver.quit()
加了一行以后会出现报错;
Traceback (most recent call last):
File "E:/py_wrok_space/study_py/6_1.py", line 11, in <module>
driver.find_element_by_id("go").submit()
File "D:\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 285, in find_element_by_id
return self.find_element(by=By.ID, value=http://www.mamicode.com/id_)
File "D:\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 787, in find_element
‘value‘: value})[‘value‘]
File "D:\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in execute
self.error_handler.check_response(response)
File "D:\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"go"}
(Session info: chrome=59.0.3071.9)
(Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 6.1.7601 SP1 x86_64)
Google以后,找到链接https://stackoverflow.com/questions/34969208/nosuchelementexception-message-unable-to-locate-element-methodlink-text
明天再解决。
Python+selenium 遇到的问题