简体   繁体   中英

NoSuchElementException when using Xpath

So I am trying to access the website and I want the program to apply some filters for me via click. Although when I try to use the function find_element_by_xpath it says that this function is depreciated. Can someone help me ? Also the website is kind of weird because it is more like a dashboard than a website and so I dont know how precise xpath will work. thank you all so much in advance

The Solution For this problem is :

using the new feature find_element() include this import too

from  selenium.webdriver.common.by import By  

this is an example :

button = driver.find_element_by_class_name("quiz_button")
button = driver.find_element(By.CLASS_NAME, "quiz_button")

please see this selenium documentation : https://www.selenium.dev/selenium/docs/api/py/api.html

driver.find_element_by_xpath('//*[@id="filtro-04"]/div/article/div[1]/div/div/qv- 
filterpane/div/div/div/div[2]/span').click()

Due to Depreciation Warning use the updated By method

driver.find_element(By.XPATH,'//*[@id="filtro-04"]/div/article/div[1]/div/div/qv- 
    filterpane/div/div/div/div[2]/span').click()

From there due to page loading.

wait = WebDriverWait(driver, 30)
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="filtro-04"]/div/article/div[1]/div/div/qv-filterpane/div/div/div/div[2]/span'))).click()

Imports:

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

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