[問題] 網頁定位卡關
各位版上的大大晚上好
我最近在學習selenium以自動登入Gmail作為練習對象,已經卡關兩天囉。
在輸入ID的時候沒什麼問題。
但在輸入Password的時候卻發現抓不到原件
我有嘗試過使用Xpath跟CSS定位都失敗。
//*[@id="password"]/div[1]/div/div[1]/input
//*[@id="password"]/div[1]/div/div[1]/div
這兩Xpath個我都嘗試過,也想過先用click在輸入,模擬真實輸入狀況。
但就是沒法輸入任何東西。下方是錯誤訊息。
NoSuchElementException: no such element: Unable to locate element:
{"method":"xpath","selector":"//*[@id="password"]/div[1]/div/div[1]/div"}
(Session info: chrome=59.0.3071.115)
(Driver info: chromedriver=2.30.477700
(0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1
x86_64)
懇請高手指導一下應該如何正確定到位。
感謝。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.195.99.225
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1498997500.A.C01.html
※ 編輯: yimean (123.195.99.225), 07/02/2017 20:53:10
→
07/02 21:44, , 1F
07/02 21:44, 1F
→
07/02 21:46, , 2F
07/02 21:46, 2F
→
07/03 01:50, , 3F
07/03 01:50, 3F
感謝兩位大大的分享,但是我還是沒法正確輸入。
下方是我的程式碼
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
chromedriver = "D:\desktop\Python3\chromedriver"
driver=webdriver.Chrome(chromedriver)
driver.get("https://accounts.google.com/ServiceLogin/identifier?service=mail&
passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ss=1&sc
c=1<mpl=default<mplcache=2&emr=1&osid=1&flowName=GlifWebSignIn&flowEntry=
AddSession")
driver.find_element_by_xpath("//*[@id='identifierId']").clear()
driver.find_element_by_xpath('//*[@id="identifierId"]').send_keys("yimean@gmai
l.com")
driver.find_element_by_xpath('//*[@id="identifierNext"]/content/span').click()
driver.find_element_by_css_selector("[type='password']").clear()
time.sleep(2)
driver.find_element_by_css_selector("[type='password']").send_keys("xxxxxxxx")
然後錯誤訊息如下:
InvalidElementStateException: invalid element state: Element is not currently
interactable and may not be manipulated
(Session info: chrome=59.0.3071.115)
(Driver info: chromedriver=2.30.477700
(0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1
x86_64)
在請大大指導一下了,感謝。
※ 編輯: yimean (123.195.99.225), 07/03/2017 08:40:33
→
07/05 01:40, , 4F
07/05 01:40, 4F
→
07/05 01:41, , 5F
07/05 01:41, 5F
→
07/05 01:41, , 6F
07/05 01:41, 6F
→
07/05 01:47, , 7F
07/05 01:47, 7F
→
07/05 16:54, , 8F
07/05 16:54, 8F
→
07/27 00:47, , 9F
07/27 00:47, 9F
→
07/27 00:47, , 10F
07/27 00:47, 10F
→
07/27 00:48, , 11F
07/27 00:48, 11F