这是我想要执行单击操作的标记。元素成功定位,click()事件也被接受,但没有执行任何操作。
<img class="pointer" id="id53" src="/images/tree/elbow-minus.gif" alt="collapse not last" onclick="$(this)[0].src='/images/ajax-indicator.gif';var wcall=wicketAjaxGet('wicket/page?1-1.IBehaviorListener.0-dashboardBody-columns-0-gadgets-1-body-content-treeTable-form-rows-4-expandLink',function() { }.bind(this),function() { }.bind(this), function() {return Wicket.$('id53') != null;}.bind(this));;return !wcall;">
码:
link_xpath = "//a[contains(text(),'git')]//parent::*/img"
driver.find_element_by_xpath(link_xpath).click()
根据你提供的HTML,它是一个<img>
标签,元素是一个动态元素。因此,要单击所需的元素,您必须引导WebDriverWait才能使元素可单击,您可以使用以下任一解决方案:
CSS_SELECTOR
:
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "img.pointer[src='/images/tree/elbow-minus.gif']"))).click()
XPATH
:
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//img[@class='pointer' and @src='/images/tree/elbow-minus.gif']"))).click()
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC