driver.find_element_by_xpath 没有在 selenium 中点击我的元素 python
driver.find_element_by_xpath does not click my element in selenium python
我尝试了很多方法,但驱动程序没有点击我的元素。
done=driver.find_element_by_xpath("//button[@class='dimapply-btn']")
driver.execute_script("arguments[0].click();", done)
我也尝试过使用 WebDriverWait。
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Done']"))).click()
我也用过(x,y)点
done = driver.find_element_by_xpath('//body')
actions.move_to_element_with_offset(done, 320, 430).click().perform()
我的html代码是:
<div class="btn-apply" data-ng-click="applyDimensionChanges()" role="button" tabindex="0">
<button class="dimapply-btn">Done</button>
</div>
它不会抛出任何错误。只是通过我的代码并且不点击。
请帮帮我。先感谢您。我正在解决这条线两天。
To click()
在文本为 Done 按钮的元素上,您可以使用以下任一项 :
使用css_selector
:
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.btn-apply[data-ng-click^='applyDimensionChanges']>button.dimapply-btn"))).click()
使用XPATH
:
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[@class='btn-apply' and starts-with(@data-ng-click, 'applyDimensionChanges')]/button[@class='dimapply-btn' and text()='Done']"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
我尝试了很多方法,但驱动程序没有点击我的元素。
done=driver.find_element_by_xpath("//button[@class='dimapply-btn']")
driver.execute_script("arguments[0].click();", done)
我也尝试过使用 WebDriverWait。
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Done']"))).click()
我也用过(x,y)点
done = driver.find_element_by_xpath('//body')
actions.move_to_element_with_offset(done, 320, 430).click().perform()
我的html代码是:
<div class="btn-apply" data-ng-click="applyDimensionChanges()" role="button" tabindex="0">
<button class="dimapply-btn">Done</button>
</div>
它不会抛出任何错误。只是通过我的代码并且不点击。 请帮帮我。先感谢您。我正在解决这条线两天。
To click()
在文本为 Done 按钮的元素上,您可以使用以下任一项
使用
css_selector
:WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.btn-apply[data-ng-click^='applyDimensionChanges']>button.dimapply-btn"))).click()
使用
XPATH
:WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[@class='btn-apply' and starts-with(@data-ng-click, 'applyDimensionChanges')]/button[@class='dimapply-btn' and text()='Done']"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC