0

Html 选择标签包含 Id。我在相对路径中使用了 id,并通过单击评估按钮在 firepath 中进行了测试。firepath 仅返回一个匹配节点,但未突出显示选择框。它清楚地表明选择框不会被处理。我尝试了很多方法,但都没有帮助我。请在下面找到html标签

<select id="myForm:operatingUnit" class="ef-combo-container" style="display:none;" name="myForm:operatingUnit">
<option value="-1">Please Select</option>
<option value="702">Industrial Casualty</option>
<option value="703">General Casualty</option>
<option value="704">Specialty Primary</option>
</select>
<input id="myForm:operatingUnit_input" class="combo-input ui-autocomplete-input" value="Please Select" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true" title="Please Select"/>

Please find the relative xpath on below:
//select[@id='myForm:operatingUnit']

我也使用了各种显式等待语句,但没有解决这个问题。请帮助我克服这个问题

4

1 回答 1

1

Select假设如何显示?在HTML代码中我可以看到css property: -

style="display:none;"

由于此属性,该元素不会显示在网页上。这里有什么问题?

如果您删除此CSS属性,则该元素将显示在网页上,并且将使用xpath您使用的 突出显示。

如果您仍想与元素交互,则必须修改元素的 css 属性,以下是修改该属性的代码:-

WebElement element = driver.findElement(By.id("myForm:operatingUnit"));
((JavascriptExecutor)driver).executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "display:unset;");

修改Select后将显示,然后您可以与之交互。

于 2016-08-02T16:52:53.873 回答