我想知道如何從值池中的下拉列表中選擇特定值。 我的邏輯是使用硒搜索並從下拉列表中選擇值Webdriver
1.Open the page
2.Fetch all the values from dropdown in list
3.Use a loop
4.Look for that value
5.If the value is not there,select the value x
對我來說,這是說沒有這樣的元素異常
它是我們需要關注的是元素第一 在我的代碼,我想選擇Nextran Corporation
下面是我的代碼
@Test(dependsOnMethods={"go2personalsettings"})
void setru()
{
driver.switchTo().frame("contentFrame");
Select rudropdown=new Select(driver.findElement(By.id("DefaultOrganisationDropDown")));
List<WebElement> drop=rudropdown.getOptions();
int e=drop.size();
String actual_ru="999425, NEXTRAN CORPORATION - JACKSONVILLE";
for(int i=0;i<e;i++)
{
String expected_ru=drop.get(i).getText();
if(!expected_ru.equals(actual_ru))
{
rudropdown.selectByValue(actual_ru);
}
}
嘗試改變'如果(!expected_ru.equals(actual_ru))''來,如果(expected_ru.equals(actual_ru))'謝謝 – DebanjanB
更換drop.get(I).getText()與drop.get( ⅰ).getAttribute( 「的innerText」)。如果這不起作用,請發佈錯誤堆棧跟蹤 –
以上解決方案都不起作用。 下拉框架和動作應該從下拉列表中選擇具體的值。 我們是否需要在這裏應用用戶操作,如移動到元素 –