我尝试了很多方法,但驱动程序未单击我的元素。
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>
它不会引发任何错误。只是通过我的代码而没有点击。请帮帮我。先感谢您。我正在为这条线解决两天。
对于文本为完成按钮的元素上的click()
,您可以使用以下Locator Strategies之一:
使用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