0
我需要選擇自動完成降下來的地址中硒的webdriver。自動完成下拉框中硒的webdriver
我已經加入了下拉框中的檢查元素源如下,
<div id="wrapper">
<ul id="ui-id-1" class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content ui-corner-all" tabindex="0" style="display: none;"/>
<div class="k-widget k-window" style="padding-top: 33px; min-width: 90px; min-height: 50px; width: 200px; display: none; top: 600px; left: 5px;" data-role="draggable">
<div class="k-widget k-window" style="padding-top: 33px; min-width: 90px; min-height: 50px; width: 200px; display: none; top: 600px; left: 5px;" data-role="draggable">
<div class="k-widget k-window" style="padding-top: 33px; min-width: 90px; min-height: 50px; width: 200px; display: none; top: 600px; left: 5px;" data-role="draggable">
<div class="datepicker datepicker-dropdown dropdown-menu" style="display: none;">
<div class="datepicker datepicker-dropdown dropdown-menu" style="display: none;">
<div class="datepicker datepicker-dropdown dropdown-menu" style="display: none;">
<div class="datepicker datepicker-dropdown dropdown-menu" style="display: none;">
<div class="datepicker datepicker-dropdown dropdown-menu" style="display: none;">
<div class="datepicker datepicker-dropdown dropdown-menu" style="display: none;">
<ul id="ui-id-2" class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content ui-corner-all" tabindex="0" style="display: none;"/>
<ul id="ui-id-3" class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content ui-corner-all" tabindex="0" style="display: none; width: 540px; top: 694.783px; left: 510px;">
<li class="ui-menu-item" role="presentation">
<a id="ui-id-704" class="ui-corner-all" tabindex="-1">SYDNEY, New South Wales, Australia, 1001</a>
</li>
<li class="ui-menu-item" role="presentation">
<a id="ui-id-705" class="ui-corner-all" tabindex="-1">SYDNEY, New South Wales, Australia, 1002</a>
</li>
<li class="ui-menu-item" role="presentation">
<a id="ui-id-706" class="ui-corner-all" tabindex="-1">SYDNEY, New South Wales, Australia, 1003</a>
</li>
<li class="ui-menu-item" role="presentation">
<a id="ui-id-707" class="ui-corner-all" tabindex="-1">SYDNEY, New South Wales, Australia, 1005</a>
</li>
<li class="ui-menu-item" role="presentation">
<li class="ui-menu-item" role="presentation">
我需要選擇「悉尼,新南威爾士,澳大利亞,1001」從自動完成框中的下拉值。請給我一些想法。我已經使用下面的代碼,但它不工作,
driver.findElement(By.id("HomeAddress_AddressLine1")).sendKeys("Walker Street");
driver.findElement(By.id("HomeAddress_City")).click();
driver.findElement(By.id("HomeAddress_City")).sendKeys("sydney");
Thread.sleep(3000);
WebElement select = driver.findElement(By.id("ui-id-3"));
java.util.List<WebElement> options = select.findElements(By.tagName("li"));
for (WebElement option1 : options) {
if("SYDNEY, New South Wales, Australia, 1001".equals(option1.getText().trim()))
option1.click();
}
Thread.sleep(2000);
請建議我如何獲得該值。這裏的問題是id值ui-id-3每次頁面重新加載時都會改變,例如(像ui-id-12,ui-id-18)。我附上了頁面的屏幕截圖。
選擇類,因爲沒有出現在DOM沒有選擇類將不會在這裏工作。您必須使用xpath或CSS來使其工作 – thebadguy