Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.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
无法使用Python中的Selenium从下拉菜单中通过xpath选择元素_Python_Selenium_Xpath_Drop Down Menu - Fatal编程技术网

无法使用Python中的Selenium从下拉菜单中通过xpath选择元素

无法使用Python中的Selenium从下拉菜单中通过xpath选择元素,python,selenium,xpath,drop-down-menu,Python,Selenium,Xpath,Drop Down Menu,我很难用Selenium从下拉菜单中选择元素 检查页面时,它看起来如下所示: <select id="numbers" name="numbers" style="display: inline-block;"> <option value="all">all numbers</option> <option value="c4ca4238a0b923820dcc509a6f75849b">One</option> <option

我很难用Selenium从下拉菜单中选择元素

检查页面时,它看起来如下所示:

<select id="numbers" name="numbers" style="display: inline-block;">
<option value="all">all numbers</option>
<option value="c4ca4238a0b923820dcc509a6f75849b">One</option>
<option value="c81e728d9d4c2f636f067f89cc14862c">Two</option>
<option value="34173cb38f07f89ddbebc2ac9128303f">Three</option>
</select>
但我收到了一个错误:

  EC.element_to_be_clickable((By.XPATH, '//*[@id="numbers"]/option[3]'))
  File "/Library/Python/2.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
Stacktrace:
    at FirefoxDriver.prototype.findElementInternal_ (file:///var/folders/7q/ttwklc8j10x_8q7yy8t2scpw0000gn/T/tmpYJKH0R/extensions/fxdriver@googlecode.com/components/driver-component.js:10770)
    at FirefoxDriver.prototype.findElement (file:///var/folders/7q/ttwklc8j10x_8q7yy8t2scpw0000gn/T/tmpYJKH0R/extensions/fxdriver@googlecode.com/components/driver-component.js:10779)
    at DelayedCommand.prototype.executeInternal_/h (file:///var/folders/7q/ttwklc8j10x_8q7yy8t2scpw0000gn/T/tmpYJKH0R/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
    at DelayedCommand.prototype.executeInternal_ (file:///var/folders/7q/ttwklc8j10x_8q7yy8t2scpw0000gn/T/tmpYJKH0R/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
    at DelayedCommand.prototype.execute/< (file:///var/folders/7q/ttwklc8j10x_8q7yy8t2scpw0000gn/T/tmpYJKH0R/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)
就我所能理解的,它无法定位xpath,即使我仔细检查了从Chrome复制/粘贴它


我错过了什么?谢谢您的帮助。

由于您必须从选择控件中选择选项,因此最好使用如下所示的选择类:

select = Select(driver.find_element_by_id("numbers"))
select.select_by_visible_text("Two")

请告诉我上述代码是否适用于您。

我认为您首先需要单击该下拉菜单,然后将显示选项

element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="numbers"]')))
element.click();

然后单击//选项[3]

我同意这是处理选定元素的最佳方法,但我猜这里还存在其他问题,如元素在IFRAME中或不可见等。这需要更多的调查。请尝试使用cssSelector selectnumbers选项:nth-child3
element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="numbers"]')))
element.click();