0
如何讓這個硒腳本知道它是否能夠登錄?目前我正在使用is_displayed()
來查看登錄表單是否仍在頁面上。有沒有更好的辦法?如何確定我的Selenium腳本是否能夠登錄?
driver.find_element_by_id("uname").send_keys("admin")
driver.find_element_by_id("pwd").send_keys("admin")
driver.find_element_by_xpath('//*[@id="login_form"]/div/button').click()
# below xpath is code for invalid user id or password message
if driver.find_element_by_xpath('//*[@id="login_form"]/div[1]').is_displayed():
output=open("OutputAdmin","w+")
output.write("Login unsuccessful")
output.close()
else:
output = open("OutputAdmin", "w+")
output.write("Login successful")
output.close()
driver.quit()
現在,如果用戶ID或密碼不正確,這是工作正常,但如果他們是正確的它不執行其他代碼。
評論在Python中使用'#' –
好吧,這是你們解釋說它是錯誤消息的xpath它沒有出現在代碼中.. –