Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.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-选择字段不会通过远程Webdrive保存_Python_Google Chrome_Selenium_Firefox - Fatal编程技术网

Python Selenium-选择字段不会通过远程Webdrive保存

Python Selenium-选择字段不会通过远程Webdrive保存,python,google-chrome,selenium,firefox,Python,Google Chrome,Selenium,Firefox,我必须测试一个用React编写的web应用程序。我想从“选择”字段中选择选项: HTML <select id="martial_status" class="form-control" name="martial_status"> <option value="" hidden="">---</option> <option value="1">wolny</option> </select> 或 它们都只能与本地web

我必须测试一个用React编写的web应用程序。我想从“选择”字段中选择选项:

HTML
<select id="martial_status" class="form-control" name="martial_status">
<option value="" hidden="">---</option>
<option value="1">wolny</option>
</select>

它们都只能与本地webdriver一起正常工作:

cls.driver = webdriver.Firefox()
cls.driver.implicitly_wait(20)
使用远程Webdriver时,所选值不会保存:

cls.driver = webdriver.Remote(
             command_executor='http://xx.xx.xx.xx:5555/wd/hub',
             desired_capabilities=DesiredCapabilities.FIREFOX)
测试未检索任何错误。从正在执行远程测试的远程服务器上启动的Seleniu_standalone_服务器控制台中,我假设可以找到select:

14:31:16.993 INFO - Executing: [find element: By.id: martial_status])
14:31:17.002 INFO - Done: [find element: By.id: martial_status]
14:31:17.063 INFO - Executing: [tag name: 15 [[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status]])
14:31:17.070 INFO - Done: [tag name: 15 [[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status]]
14:31:17.130 INFO - Executing: [get element attribute: 15 [[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status], multiple])
14:31:17.143 INFO - Done: [get element attribute: 15 [[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status], multiple]
14:31:17.204 INFO - Executing: [find child elements: 15 [[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status], By.cssSelector: option[value ="1"]])
14:31:17.212 INFO - Done: [find child elements: 15 [[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status], By.cssSelector: option[value ="1"]]
14:31:17.272 INFO - Executing: [is selected: 16 [[[[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status]] -> css selector: option[value ="1"]]])
14:31:17.278 INFO - Done: [is selected: 16 [[[[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status]] -> css selector: option[value ="1"]]]
14:31:17.337 INFO - Executing: [click: 16 [[[[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status]] -> css selector: option[value ="1"]]])
14:31:17.376 INFO - Done: [click: 16 [[[[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status]] -> css selector: option[value ="1"]]]
但在保存并重新输入后,我看到没有设置select。 相同的代码、本地webdriver和所选字段都正常。
谁能解决这个问题

您可以使用相对XPath来选择元素。 i、 e.//选项[@value='1']


参考资料:

至少在您的示例中,您缺少了一个右括号。id是教育,而不是军事状态。对不起,问题不完整,单击错误,我将其发送给early:@JeremyGarrell我将错误的选择复制到示例中
cls.driver = webdriver.Remote(
             command_executor='http://xx.xx.xx.xx:5555/wd/hub',
             desired_capabilities=DesiredCapabilities.FIREFOX)
14:31:16.993 INFO - Executing: [find element: By.id: martial_status])
14:31:17.002 INFO - Done: [find element: By.id: martial_status]
14:31:17.063 INFO - Executing: [tag name: 15 [[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status]])
14:31:17.070 INFO - Done: [tag name: 15 [[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status]]
14:31:17.130 INFO - Executing: [get element attribute: 15 [[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status], multiple])
14:31:17.143 INFO - Done: [get element attribute: 15 [[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status], multiple]
14:31:17.204 INFO - Executing: [find child elements: 15 [[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status], By.cssSelector: option[value ="1"]])
14:31:17.212 INFO - Done: [find child elements: 15 [[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status], By.cssSelector: option[value ="1"]]
14:31:17.272 INFO - Executing: [is selected: 16 [[[[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status]] -> css selector: option[value ="1"]]])
14:31:17.278 INFO - Done: [is selected: 16 [[[[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status]] -> css selector: option[value ="1"]]]
14:31:17.337 INFO - Executing: [click: 16 [[[[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status]] -> css selector: option[value ="1"]]])
14:31:17.376 INFO - Done: [click: 16 [[[[FirefoxDriver: Firefox on LINUX (661c3804-f7e8-470a-b516-95ad449efb8b)] -> id: martial_status]] -> css selector: option[value ="1"]]]