Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.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
Java 根据selenium中的选项组选择特定选项_Java_Angularjs_Selenium - Fatal编程技术网

Java 根据selenium中的选项组选择特定选项

Java 根据selenium中的选项组选择特定选项,java,angularjs,selenium,Java,Angularjs,Selenium,希望这不会重复。我在网上搜索,但找不到我需要的确切答案。我有一个选项组的下拉列表。我需要根据输入选项组“主要借款人”或“共同借款人”从下拉列表中选择一个值,然后继续。你能帮我做这件事吗 这是角度代码 <select name="selected-borrower" id="selected-borrower" data-ng-model="BorrowerCtrl.selected" data-ng-options="borrower.getFullName() group by bor

希望这不会重复。我在网上搜索,但找不到我需要的确切答案。我有一个选项组的下拉列表。我需要根据输入选项组“主要借款人”或“共同借款人”从下拉列表中选择一个值,然后继续。你能帮我做这件事吗

这是角度代码

<select name="selected-borrower" id="selected-borrower" data-ng-model="BorrowerCtrl.selected" data-ng-options="borrower.getFullName() group by borrower.getGroup() for borrower in BorrowerCtrl.borrowers | borrowerSort" data-ng-disabled="BorrowerCtrl.selected.updateInProgress" class="ng-pristine ng-valid ng-not-empty ng-touched" aria-invalid="false" style="">
  <optgroup label="Primary Borrower">
    <option label="CLAUDINE G SELSER" value="object:1426" selected="selected">Person One</option>
  </optgroup>
  <optgroup label="Co-Borrower">
    <option label="LEOTA N MACHUCA" value="object:1427">Person Two</option>
  </optgroup>
</select>

第一个人
二号人物

非常感谢您的帮助。

XPath是解决方案

WebDriver.findElement(By.xpath("//select[@id='selected-borrower']/optgroup[@label='Primary Borrower']/option")).click();

简单地说,这个XPath从id为“selected borrower”的select元素遍历到标签为“Primary borrower”的optgroup,并选择第一个选项(在本例中是标签为“CLAUDINE G SELSER”的选项)。如果您愿意,您可以修改
@label=
部分为共同借款人工作

您是否尝试过选择如下所示的类:

 Select select = new Select(driver.findElement(By.id("selected-borrower")));
 select.selectByVisibleText("CLAUDINE G SELSER");

请阅读并提供您尝试过的代码和执行结果,包括任何错误消息等。谢谢@Dean。这使事情顺利进行。我导航到“选项”,但没有得到点击的想法,现在我从你的帮助得到了它。