2016-12-26 53 views
1

我目前正在嘗試打開登錄頁面,它是'',以填寫'用戶名'和'密碼'字段,然後單擊'登錄',所有這些都是通過Python和Selenium自動完成的。使用Python 3.5和Se自動登錄網站

但我甚至無法填寫第一個文本格式,即用戶名。

這裏是我的代碼:

from selenium import webdriver 
from selenium.webdriver.common.by import By 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 

driver = webdriver.Chrome() 
driver.get('') 

wait = WebDriverWait(driver, 5) 
user = wait.until(EC.visibility_of_element_located((By.ID, 'userid'))) 

user.clear() 
user.send_keys('[email protected]') 

這給了我下面的錯誤:

Traceback (most recent call last): File "/Users/michael/PycharmProjects/project/doc.py", line 10, in user = wait.until(EC.visibility_of_element_located((By.ID, 'userid'))) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/support/wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:

我如何填寫這些表格2?

回答

0

你可以這樣說:

from selenium import webdriver 

driver = webdriver.Chrome() 
driver.get('https://signin.ebay.co.uk/ws/eBayISAPI.dll') 

elements = driver.find_elements_by_class_name("fld") 
elements[2].send_keys("username") 
elements[3].send_keys("password") 

button = driver.find_element_by_id("sgnBt") 
button.click() 
+0

太感謝你了!你介意告訴我如何點擊'登錄'按鈕?我嘗試**按鈕= driver.find_element_by_class_name('sgnBtn')**後跟**按鈕[0] .click()**,但它不工作,並給我** TypeError:'WebElement'對象不支持索引* *謝謝 – Michael

+0

將代碼添加到答案。我很高興這很有幫助,請考慮將答案標記爲有助於結束該主題 – Hisagr