Python 在selenium中很难按下按钮
如何按下“全部”按钮Python 在selenium中很难按下按钮,python,selenium,xpath,css-selectors,webdriverwait,Python,Selenium,Xpath,Css Selectors,Webdriverwait,如何按下“全部”按钮 <label for="f_agreements_all"> <input type="checkbox" id="f_agreements_all"> <span></span> <span class="permText">I accept all</span>
<label for="f_agreements_all">
<input type="checkbox" id="f_agreements_all">
<span></span>
<span class="permText">I accept all</span>
</label>
不幸的是,找到f_agreements_all按钮并单击它并不起作用。Span覆盖了整个按钮17x17px,而f_和f_下的所有按钮都是16x16。您知道单击它的可能方式吗?请尝试下面的xpath:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
button=WebDriverWait(browser, 10).until(
EC.element_to_be_clickable((By.XPATH, "//li[@class='formCheckbox agreements all-agreements']//span[1]")))
button.click()
请尝试下面的xpath:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
button=WebDriverWait(browser, 10).until(
EC.element_to_be_clickable((By.XPATH, "//li[@class='formCheckbox agreements all-agreements']//span[1]")))
button.click()
使用vanilla JS的一种方法是:
const checkbox = document.getElementById('f_agreements_all');
checkbox.click();
快速查看文档,您可以尝试:
driver.find_element_by_id("f_agreements_all").click()
使用vanilla JS的一种方法是:
const checkbox = document.getElementById('f_agreements_all');
checkbox.click();
快速查看文档,您可以尝试:
driver.find_element_by_id("f_agreements_all").click()
要单击该元素,您必须引导WebDriverWait使该元素可单击,并且您可以使用以下任一解决方案: 使用CSS_选择器: 使用XPATH: 注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
要单击该元素,您必须引导WebDriverWait使该元素可单击,并且您可以使用以下任一解决方案: 使用CSS_选择器: 使用XPATH: 注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
也许用javascript来点击它。你能告诉我怎么做吗?我只知道如何使用python,不知道javascriptselenium有driver.execute_script一些javascript代码我在下面添加了一种方法,但我会编辑您的问题,说明您是如何找到按钮并单击它的,以及您尝试了哪些其他方法。还可以添加您正在使用的Selenium版本。可以使用javascript单击它。您能告诉我如何操作吗?我只知道如何使用python,不知道javascriptselenium有driver.execute_script一些javascript代码我在下面添加了一种方法,但我会编辑您的问题,说明您是如何找到按钮并单击它的,以及您尝试了哪些其他方法。同时添加您正在使用的Selenium版本。不幸的是,此错误发生在raise TimeoutExceptionmessage、screen、stacktrace Selenium.common.exceptions.TimeoutException:Message:您可以共享您的url吗?如果没有,请检查元素是否在iframe中。不幸的是,此错误发生在raise TimeoutExceptionmessage,screen,stacktrace selenium.common.exceptions.TimeoutException:Message:您可以共享您的url吗?如果没有,请检查元素是否在iframe中