[英]Selenium WebDriver: Not able to select the element from the drop down list using webdriver
I have two dropdown list in my application, Second dropdown becomes enable after selecting the 1st dropdown. 我的应用程序中有两个下拉列表,选择第一个下拉列表后,第二个下拉列表变为启用状态。 Problem i am facing is my code is able to select the value from the 1st drop down but it is not selecting the value from the 2nd drop down.
我面临的问题是我的代码能够从第一个下拉列表中选择值,但无法从第二个下拉列表中选择值。 I am getting error as :
我收到以下错误消息:
Exception in thread "main" org.openqa.selenium.InvalidElementStateException: Element must not be hidden, disabled or read-only (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 138 milliseconds 线程“主”中的异常org.openqa.selenium.InvalidElementStateException:元素不得隐藏,禁用或只读(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:138毫秒
I have tried wait as well after selecting the 1st dropdown but still getting this error. 选择第一个下拉菜单后,我也尝试等待,但仍然收到此错误。
My Java code: 我的Java代码:
Code for 1st dropdown: 第一个下拉代码:
WebElement combo= d1.findElement(By.name("ctl00$ContentPlaceHolder1$ddlAgency"));
System.out.println("proerty name for agent:" +combo);
combo.sendKeys("huma");
//d1.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Thread.sleep(200);
Code for 2nd drop down: 第二个下拉代码:
WebElement combo1=d1.findElement(By.name("ctl00$ContentPlaceHolder1$ddlCountry"));
System.out.println("proerty name for country:" +combo1);
combo1.clear();
combo1.click();
combo1.sendKeys("Test");
HTML for the 2nd dropdown: 第二个下拉列表的HTML:
<select id="ctl00_ContentPlaceHolder1_ddlCountry" style="width:450px;" onchange="fillval();" name="ctl00$ContentPlaceHolder1$ddlCountry">
Error: Exception in thread "main" org.openqa.selenium.InvalidElementStateException: Element must not be hidden, disabled or read-only (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 138 milliseconds 错误:线程“主”中的异常org.openqa.selenium.InvalidElementStateException:元素不得隐藏,禁用或只读(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:138毫秒
Try using the Select
Class for the second dropdown. 尝试将
Select
Class用于第二个下拉列表。
WebElement combo1 = driver.findElement(By.name(ctl00$ContentPlaceHolder1$ddlCountry));
Select secondDrpDwn = new Select(combo1);
secondDrpDwn.selectByValue("Test");
finally i got the work around to my problem. 终于我解决了我的问题。 sharing it so that it will help others as well.
分享它,以便对他人也有帮助。 following code is working for me.
以下代码为我工作。
WebElement dropDownListBox =d1.findElement(By.cssSelector("option[value=\"Please Select Country\"]"));
dropDownListBox.click();
WebElement combo1=d1.findElement(By.name("ctl00$ContentPlaceHolder1$ddlCountry"));
System.out.println("proerty name for country:" +combo1);
combo1.click();
Select secondDrpDwn = new Select(combo1);
secondDrpDwn.selectByVisibleText("Test");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.