Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium webdriver 在我得到';找不到元素';尝试单击在单击时展开的按钮时出错_Selenium Webdriver_Xpath_Css Selectors_Python 3.6_Webdriverwait - Fatal编程技术网

Selenium webdriver 在我得到';找不到元素';尝试单击在单击时展开的按钮时出错

Selenium webdriver 在我得到';找不到元素';尝试单击在单击时展开的按钮时出错,selenium-webdriver,xpath,css-selectors,python-3.6,webdriverwait,Selenium Webdriver,Xpath,Css Selectors,Python 3.6,Webdriverwait,我试图单击一个按钮,该按钮在单击时展开,但selenium无法找到该元素。确定的要素似乎是正确的。我在这里使用的是页面对象模型 我试图首先简单地找到元素并单击它,然后尝试使用ActionChains。尝试更改元素值和标识方法,如ID、XPath、CSS选择器,但似乎没有任何效果 HTML: 预期结果: 实际结果: 所需元素是动态元素,因此要在元素上单击(),您必须引导WebDriverWait使元素可单击(),并且您可以使用以下任一选项: 使用CSS\u选择器: WebDriverWait(

我试图单击一个按钮,该按钮在单击时展开,但selenium无法找到该元素。确定的要素似乎是正确的。我在这里使用的是页面对象模型

我试图首先简单地找到元素并单击它,然后尝试使用ActionChains。尝试更改元素值和标识方法,如ID、XPath、CSS选择器,但似乎没有任何效果

HTML:

预期结果:

实际结果:

所需元素是动态元素,因此要在元素上单击(),您必须引导WebDriverWait使
元素可单击()
,并且您可以使用以下任一选项:

  • 使用
    CSS\u选择器

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.expand i.fa.fa-plus-circle[id^='expand_']"))).click()
    
  • 使用
    XPATH

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='expand']//i[@class='fa fa-plus-circle' and starts-with(@id, 'expand_')]"))).click()
    
  • 注意:您必须添加以下导入:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='expand']//i[@class='fa fa-plus-circle' and starts-with(@id, 'expand_')]"))).click()
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC