[英]How to locate and click on the Accept All button using Selenium
When I call the <div>
tag and his class value then it does not response.当我调用<div>
标签和他的 class 值时,它没有响应。
HTML: HTML:
<div id="ccmgt_explicit_accept" class="privacy-prompt-button primary-button ccmgt_accept_button ">
<span>Accept All</span>
</div>
Snapshot of the element:元素快照:
To click on Accept All you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies :要单击Accept All ,您需要为element_to_be_clickable()引入WebDriverWait ,您可以使用以下任一定位器策略:
Using CSS_SELECTOR :使用CSS_SELECTOR :
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#ccmgt_explicit_accept > span"))).click()
Using XPATH :使用XPATH :
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Accept All']"))).click()
Note : You have to add the following imports:注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.