Selenium WebDriverとWebElementを使用して階層から値を取得するには? Web ページ アプリケーションは Telerik モデルです。
私のJavaコードの一部:
public void ChangeElementSaveAndVerify() throws InterruptedException
{
driver.findElement(By.xpath(myPrinterTab.printerTabIconLeftPane)).click();
Thread.sleep(5000);
driver.findElement(By.xpath(myPrinterTab.showHideDriverDetailed)).click();
Thread.sleep(5000);
WebElement select = driver.findElement(By.id("ctl00_ContentPlaceHolder2_RadGrid_Driver_ctl00_ctl05_EditFormControl_Preton_ucSettings_Driver_treeList_ctl04_Enabled_DropDown"));
WebElement innerElemt = select.findElement(By.tagName("div"));
WebElement innerElemt2 = innerElemt.findElement(By.tagName("ul"));
List<WebElement> allOptions = innerElemt2.findElements(By.tagName("li"));
for (WebElement option : allOptions) {
System.out.println("Value is: "+ option.getText());
System.out.println(option.getAttribute("value"));
driver.findElement(By.xpath(myPrinterTab.arrowUsePreton)).click();
Thread.sleep(5000);
option.click();
Thread.sleep(5000);
driver.findElement(By.xpath(myPrinterTab.saveButton)).click();
}
ページのソース
<div class="rcbSlide" style="z-index: 6000; visibility: visible; display: block; overflow: visible; margin-left: 0px; position: absolute; top: 328px; left: 1122.5px; height: 42px; width: 370px;">
<div id="ctl00_ContentPlaceHolder2_RadGrid_Driver_ctl00_ctl05_EditFormControl_Preton_ucSettings_Driver_treeList_ctl08_GraphicMode_DropDown" class="RadComboBoxDropDown RadComboBoxDropDown_Default " style="display: block; visibility: visible; top: 0px; left: 0px; width: 368px;">
<div class="rcbScroll rcbWidth" style="width: 100%; overflow: auto; height: 40px;">
<ul class="rcbList" style="list-style:none;margin:0;padding:0;zoom:1;">
<li class="rcbItem "> … </li>
<li class="rcbHovered "> … </li>
</ul>
</div>
</div>
</div>