我有一个按钮,我必须点击它,但问题是我不能点击它,直到或除非我通过使用Inspection看到它。
这是相同的Xpath。
//*[@id="react-root"]/section/main/div/header/section/div[1]/div[1]/span/span[1]/button
完整的xpath是
/html/body/div[1]/section/main/div/header/section/div[1]/div[1]/span/span[1]/button
外部HTML是
<button class="_5f5mN jIbKX _6VtSN yZn4P ">GET</button>
我使用了一些方法。
br.find_element_by_xpath(xpath)
br.find_element_by_xpath('//span [@type='button']
但它表示不存在任何元素。如何使用硒点击它?
诱导WebDriverWait
((和presence_of_element_located
((以及随后的xpath
WebDriverWait(br,20).until(EC.presence_of_element_located((By.XPATH,"//button[text()='GET']"))).click()
导入以下库。
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
如果正常的webdriver
点击不起作用,则诱导javascripts
执行器。
btn=WebDriverWait(br,20).until(EC.presence_of_element_located((By.XPATH,"//button[text()='GET']")))
br.execute_script("arguments[0].click();", btn)