我有两个下拉框。我从第一个下拉列表中选择了项目,但无法从第二个下拉框中选择值。我用过镀铬驱动程序。
这是我的代码。
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");
WebDriver driver =new ChromeDriver();
driver.get("http://localhost/ProtoD/Login.aspx");
driver.manage().window().maximize();
driver.findElement(By.id("cmbBranch_Arrow")).click();
Thread.sleep(4000);
List<WebElement> drops=driver.findElements(By.tagName("li"));
System.out.println(drops.size());
for(WebElement obj:drops){
System.out.println(obj.getText());
if(obj.getText().equalsIgnoreCase("Head Office"))
{
obj.click();
break;
}
}
driver.findElement(By.id("cmbFinYear_Arrow")).click();
Thread.sleep(4000);
List<WebElement> drops1=driver.findElements(By.tagName("li"));
System.out.println(drops1.size());
for(WebElement obj1:drops1)
{
System.out.println(obj1.getText());
if(obj1.getText().equalsIgnoreCase("01-Apr-2015--31-Mar-2016"))
{
obj1.click();
break;
}
我收到如下错误: -
未知错误:元素在点(847,271)
时无法点击
我的HTML代码: -
<input id="cmbFinYear_ClientState" name="cmbFinYear_ClientState" type="hidden" autocomplete="off" value="{"logEntries":[],"value":-2147483644,"text":"01-Apr-2015--31-Mar-2016","enabled":true}">
答案 0 :(得分:0)
变量“option”在哪里声明代码?看起来您需要使用obj1更改选项,并且最好在下面的代码段中添加EqualsIgnoreCase:
for(WebElement obj1:drops1)
{
System.out.println(obj1.getText());
if("01-Apr-2015--31-Mar-2016".equalsIgnoreCase(obj1.getText()))
option.click();
}
答案 1 :(得分:0)
使用以下代码进行点击:
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", obj1);
您可以尝试以下代码:
driver.findElement(By.id("cmbFinYear_Arrow")).click();
Thread.sleep(4000);
List < WebElement > drops1 = driver.findElements(By.tagName("li"));
System.out.println(drops1.size());
for (WebElement obj1: drops1) {
System.out.println(obj1.getText());
if (obj1.getText().equalsIgnoreCase("01-Apr-2015--31-Mar-2016")) {
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", obj1);
}