我有一个奇怪的问题。我有一个非选择下拉列表,其ID如下。在该字段的代码中没有选择标记,只有输入标记,在选择值后,也看不到DOM下拉列表中包含的文本。 StaffSoCategory 是文本框, SelectStaffSoCategory 是下拉箭头的图标, StaffSoCategoryValue 我相信是用于显示的值。
<input type="text" id="StaffSoCategory" style="width: 126px; font-weight: lighter; border: 1px solid gray; height: 25px; float: left; font-size: 12px; color: black; font-family: Arial; background-color: white;" readonly="readonly" class="ui-autocomplete-input" autocomplete="off" disabled="disabled">
<span role="status" aria-live="polite" class="ui-helper-hidden-accessible">4 results are available, use up and down arrow keys to navigate.</span>
<div id="SelectStaffSoCategory" tabindex="0" style="border-style: solid; border-width: 1px 1px 1px 0px; border-color: gray; width: 22px; height: 29px; background-position: center; cursor: pointer; background-image: url('Images/dropdown.png'); background-repeat: no-repeat; float: left; margin-left: 0px; "></div>
***<input id="StaffSoCategoryValue" type="hidden" value="">***
<ul class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" id="ui-id-4" tabindex="0" aria-disabled="false" style="z-index: 1; display: none; top: 584px; left: 829px; width: 148px;"></ul>
一旦我选择了第一个下拉值(下拉菜单中的可见文本为“已确认”),那么值就会出现在标记中,而不是我看到的值的可见文本,如下所示:
<input id="StaffSoCategoryValue" type="hidden" value="BCK-Yes">
有没有一种方法可以单击下拉菜单中的第一个值,而我尝试使用此值“ BCK-Yes”,并且该元素表示不可见。我尝试通过ID选择输入,然后尝试按键,然后按键输入也不起作用。
我正在尝试的代码是
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement revenuePotential = driver.findElement(By.id("SelectStaffSoCategory")); revenuePotential.click();
WebElement revenuePotentialValue = driver.findElement(By.id("StaffSoCategoryValue"));
js.executeScript("arguments[0].click();", revenuePotentialValue);
我遇到的控制台错误
StaffSoJsFun.js?v=2019020100000:1 Uncaught TypeError: $(...).autocomplete is not a function
at HTMLDivElement.<anonymous> (StaffSoJsFun.js?v=2019020100000:1)
at HTMLDivElement.dispatch (jquery-2.0.0.js?v=2019020100000:25)
at HTMLDivElement.y.handle (jquery-2.0.0.js?v=2019020100000:25)
(anonymous) @ StaffSoJsFun.js?v=2019020100000:1
dispatch @ jquery-2.0.0.js?v=2019020100000:25
y.handle @ jquery-2.0.0.js?v=2019020100000:25
Access to XMLHttpRequest at '' from origin 'xx.com' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
答案 0 :(得分:0)
好吧,输入是隐藏的,所以硒不会告诉您元素不可见并不令我感到惊讶。模拟诸如element
和WebDriver driver= new ChromeDriver();
JavascriptExecutor js = (JavascriptExecutor)driver;
driver.get(desiredURL);
//do all the stuff you want to do before `executeScript()`
js.executeScript("arguments[0].click();", element);
之类的用户操作的方法将无法影响隐藏的元素。但是,我认为以下方法可能会起作用:
首先将该元素存储在对象中,假设为 client.begin("IP_ADDRESS_OF_BROKER", net);
,然后尝试以下代码单击该隐藏元素:
<div id="svg-1">
<svg class="svg">
<path class="svg-path" some-path/>
<path class="svg-path" some-other-path>
</svg>
<h4 class="legende">Some text</h4>
<p class="legende">Some other text</p>
</div>
<div id="svg-2">
<svg class="svg">
<path class="svg-path" some-path/>
<path class="svg-path" some-other-path>
</svg>
<h4 class="legende">Some text</h4>
<p class="legende">Some other text</p>
</div>
<div id="svg-3">
<svg class="svg">
<path class="svg-path" some-path/>
<path class="svg-path" some-other-path>
</svg>
<h4 class="legende">Some text</h4>
<p class="legende">Some other text</p>
</div>
给个镜头吗?