驱动程序查找元素

时间:2019-04-05 12:09:31

标签: python selenium selenium-webdriver webdriver

我试图单击一个按钮,但是我的代码不起作用。这是按钮。

<button class="artdeco-button artdeco-button--secondary artdeco-button--3 mr1"> </button>

我尝试过的方法:
 driver.find_element_by_css_selector(".mr1").click()

driver.find_element_by_class_name("artdeco-button").click()

我每次遇到的错误是:selenium.common.exceptions.ElementClickInterceptedException: Message: Element <span class="search-vertical-filter__dropdown-trigger-text mr1"> is not clickable at point (151,80) because another element <div class="modal-wormhole-overlay "> obscures it

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

selenium.common.exceptions.ElementClickInterceptedException: Message: Element <span class="search-vertical-filter__dropdown-trigger-text mr1"> is not clickable at point (151,80) because another element <div class="modal-wormhole-overlay "> obscures it

因为类别名称为mr1的标签还有一个标签,因此也可以使用。

driver.find_element_by_css_selector(“ tagname.classname”)。click()

driver.find_element_by_css_selector("button.mr1").click()

OR

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
WebDriverWait(driver, 10).until(expected_conditions.element_to_be_clickable((By.CSS_SELECTOR,"button.mr1"))).click()