1

我使用Selenium 3.0和Firefox 48來自動化應用程序。但在firefox48,自動選擇下拉不起作用。選擇下拉不能在Firefox 48中使用硒webdriver

對於IE和Chrome,相同的代碼工作正常。

這是瀏覽器或我的代碼問題?

enter image description here

Select sel = new Select(driver.findElement(By.xpath("//select[contains(@id,'BusinessUnit')]"))); 
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ctl00_vmsContent_rdwBusinessUnit_C_selBusinessUnit"))); 
List<WebElement> list = sel.getOptions(); 
for (WebElement el : list) 
{ 
    System.out.println(el.getText()); 
    sel.selectByIndex(2); 
} 
+0

試試這個答案http://stackoverflow.com/questions/39224373/unable-to-select-dropdown-option-after-updating-jar-files-to-selenium-3-0/39228389#39228389 –

+0

@naveen,你有什麼錯誤嗎? –

回答

0

我會精簡代碼一點。我添加了一些用於調試的代碼。

// wait until returns a WebElement, store it for later use 
WebElement e = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[contains(@id,'BusinessUnit')]"))); 
// dump the HTML of the select element and make sure you have the element you are expecting 
System.out.println(e.getAttribute("outerHTML")); 
Select sel = new Select(e); 
for (WebElement el : sel.getOptions()) 
{ 
    System.out.println(el.getText()); 
} 
sel.selectByIndex(2); // pull this out of the loop or it will get selected mutliple times 
// other options for selecting the desired OPTION 
sel.selectByValue("12"); 
sel.selectByVisibleText("Engineering"); 
+0

你有什麼解決方案嗎? – HemaSundar

+0

@HemaSundar當然,在我上面的答案。我很困惑你在問什麼。 – JeffC

相關問題