Selenium webdriver 无法通过Katalon Studio中的索引在下拉列表中选择值
我目前正在使用Katalon Studio自动化一个用例,其中包括下拉菜单上的操作 我确信我正确地编写了自动化代码,但由于某些原因,我发现我的代码没有按预期工作。在DropdownByIndex中选择选项的代码既不工作也不生成任何异常。但当我使用相同的代码在下拉列表中通过可见文本选择选项时,它似乎工作得很好 下面是我的代码。请仔细研究一下,并向我建议一些替代方案,通过索引对下拉菜单进行操作,从而自动化用例Selenium webdriver 无法通过Katalon Studio中的索引在下拉列表中选择值,selenium-webdriver,ui-automation,katalon-studio,Selenium Webdriver,Ui Automation,Katalon Studio,我目前正在使用Katalon Studio自动化一个用例,其中包括下拉菜单上的操作 我确信我正确地编写了自动化代码,但由于某些原因,我发现我的代码没有按预期工作。在DropdownByIndex中选择选项的代码既不工作也不生成任何异常。但当我使用相同的代码在下拉列表中通过可见文本选择选项时,它似乎工作得很好 下面是我的代码。请仔细研究一下,并向我建议一些替代方案,通过索引对下拉菜单进行操作,从而自动化用例 String FeeTypeDropDownInAddFeeSidePanelXpath
String FeeTypeDropDownInAddFeeSidePanelXpath = "//select[@name='serviceLevelFee']"
String ServiceDropDownInAddFeeSidePanelXpath = "//select[@name='service']"
public void addFee(int FeeTypeIndex,int ServiceIndex)
{
//the below works
rbu.clickOnWebElement(AddFeeButtonXpath)
WebUI.delay(5)
println ("selecting Fee type from the respective drop down")
selectAValueInDropdownByIndex(FeeTypeDropDownInAddFeeSidePanelXpath,FeeTypeIndex)
WebUI.delay(5)
println ("selecting Service from the respective drop down")
selectAValueInDropdownByIndex(ServiceDropDownInAddFeeSidePanelXpath,ServiceIndex)
WebUI.delay(5)
// the below works
rbu.clickOnWebElement(SaveButtonInAddFeeSidePanelXpath)
WebUI.delay(5)
}
public void selectAValueInDropdownByIndex(String xpath,int index)
{
//this method selects a option in drop down by its index
//taking the elements xpath and index as parameters.also handels the StaleElementReferenceException which
// is observed redundant thru RRm drop down web elements
try{
println ("inside try")
String elementXpath = xpath
WebElement webelement = driver.findElement(By.xpath(elementXpath))
Select webelementSelect = new Select(webelement)
webelementSelect.selectByIndex(index)
}
catch(StaleElementReferenceException e)
{
println ("inside catch of StaleElementReferenceException")
String elementXpath = xpath
WebElement webelement = driver.findElement(By.xpath(elementXpath))
Select webelementSelect = new Select(webelement)
webelementSelect.selectByIndex(index)
}
catch(NoSuchElementException e)
{
println("NoSuchElementException raised")
while (true)
{
String elementXpath = xpath
WebDriverWait wait = new WebDriverWait(driver,35)
WebElement webelement = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(elementXpath)))
Select webelementSelect = new Select(webelement)
webelementSelect.selectByValue(index)
if(!webelement.isDisplayed())
{
break
//option selected in the drop down
}
}
}
}