简体   繁体   中英

Problem in finding the element using the xPath using selenium in python

I want to log-in the page and click the button which is located on top of the website but when i run code it says that element could not be found, below is my python code:

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://go.xero.com/Dashboard")
user_name = driver.find_element_by_id("email")
user_name.send_keys("mnb@allied.ae")
password = driver.find_element_by_id("password")
password.send_keys()
Submit = driver.find_element_by_id("submitButton")
Submit.click()
CS = driver.find_element_by_xpath("//span[@class='xrh-appbutton--text']")
cs.click()

driver.quit() 

below is the HTML source code:

在此处输入图片说明

Seems it requires some time to find the elements. To manage this you need to implement wait mechanism in your scripts. Use either implicit or explicit waits. refer this

Implicit Wait

driver.get("https://go.xero.com/Dashboard")
driver.implicitly_wait(15)

Explicit Wait

cs = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//span[@class='xrh-appbutton--text']")))
cs.click()

Need to import following packages for this -

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM