Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java selenium中选择下拉列表时出现元素未找到错误_Java_Firefox_Drop Down Menu_Selenium Webdriver - Fatal编程技术网

在Java selenium中选择下拉列表时出现元素未找到错误

在Java selenium中选择下拉列表时出现元素未找到错误,java,firefox,drop-down-menu,selenium-webdriver,Java,Firefox,Drop Down Menu,Selenium Webdriver,这是我写的代码 当weblist从下拉列表中选择第二个用户时,我得到以下错误 由于在缓存中找不到元素导致-可能该页在查找后已更改 代码是 import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.o

这是我写的代码 当weblist从下拉列表中选择第二个用户时,我得到以下错误 由于在缓存中找不到元素导致-可能该页在查找后已更改

代码是

import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class SimpleBrowseroperation 
{

public static void main(String[] args) throws InterruptedException 
{
    WebDriver driver = new FirefoxDriver();
    //WebDriver driver = new InternetExplorerDriver();
    //WebDriver driver = new ChromeDriver();        
    //driver.navigate().to("https://google.co.in");
    driver.navigate().to("https://testnwadmin.aditi.com/nwadmin/spages/home.aspx");
    List<WebElement> ele = driver.findElements(By.xpath("//*[@id='divLoginSection']/div/div[3]"));
    driver.findElement(By.id("Login1_txtEmailID")).sendKeys("testdata5@aditi.com");
    //driver.findElement(By.id("Login1_txtPassword")).sendKeys("Testing1*");
    driver.findElement(By.id("Login1_btnLogin")).click();
    driver.findElement(By.xpath("//*[@id='sliding-navigation']/li[2]/a")).click();
    String ViewMorelink="//*[@id='divContentHolder']/div[2]/table[%s]/tbody/tr[3]/td";
    String ClkViewMore="//*[@id='divContentHolder']/div[2]/table[%s]/tbody/tr[3]//a[contains(text(),'View')]";
    String Covered="//*[@id='divContentHolder']/div[2]/table[%s]/tbody/tr[2]/td/table/tbody/tr[%s]/td[2]";
    String ViewDetails="//*[@id='divContentHolder']/div[2]/table[%s]/tbody/tr[2]/td/table/tbody/tr[%s]/td[3]/a";
    String TableRowCount="//*[@id='divContentHolder']/div[2]/table[%s]/tbody/tr[2]/td/table/tbody/tr";
    String ViewCarrier="//*[@id='divContentHolder']/div[2]/table[%s]/tbody/tr[2]/td/table/tbody/tr[%s]/td[3]";
    String ClaimPayer="//*[@id='divContentHolder']/div[2]/table[%s]/tbody/tr[2]/td/table/tbody/tr[%s]/td[4]";

    Select WebList=new Select(driver.findElement(By.xpath("//*[@id='ddlSelectUser']")));
    List<WebElement> userlist = WebList.getOptions();
    int usercnt=userlist.size();
    System.out.println(usercnt);
    String[] linkTexts = new String[usercnt];
    int i = 0;
    for (WebElement e : userlist) 
    {
    linkTexts[i] = e.getText();
    i++;
    }
    for(int usrcnt=0;usrcnt<=usercnt;usrcnt++)
    {

        WebList.selectByIndex(usrcnt);
        > /
                    > somecode
                    > /

    }

}
}
import java.util.List;
导入java.util.concurrent.TimeUnit;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.WebElement;
导入org.openqa.selenium.chrome.ChromeDriver;
导入org.openqa.selenium.firefox.FirefoxDriver;
导入org.openqa.selenium.support.ui.Select;
公共类SimpleBrowseroperation
{
公共静态void main(字符串[]args)引发InterruptedException
{
WebDriver=newfirefoxdriver();
//WebDriver驱动程序=新的InternetExplorerDriver();
//WebDriver驱动程序=新的ChromeDriver();
//驱动程序。导航()。到(“https://google.co.in");
驱动程序。导航()。到(“https://testnwadmin.aditi.com/nwadmin/spages/home.aspx");
List ele=driver.findElements(By.xpath(“/*[@id='divLoginSection']]/div/div[3]”);
driver.findElement(By.id(“Login1_txtEmailID”)).sendKeys(“testdata5@aditi.com");
//driver.findElement(By.id(“Login1_txtPassword”)).sendKeys(“Testing1*”);
driver.findElement(By.id(“Login1_btnLogin”)。单击();
findElement(By.xpath(“//*[@id='slide-navigation']/li[2]/a”)。单击();
字符串ViewMorelink=“//*[@id='divContentHolder']/div[2]/table[%s]/tbody/tr[3]/td”;
字符串ClkViewMore=“//*[@id='divContentHolder']/div[2]/表[%s]/tbody/tr[3]///a[contains(text(),'View')”;
字符串Covered=“//*[@id='divContentHolder']/div[2]/table[%s]/tbody/tr[2]/td/table/tbody/tr[%s]/td[2]”;
字符串ViewDetails=“//*[@id='divContentHolder']/div[2]/table[%s]/tbody/tr[2]/td/table/tbody/tr[%s]/td[3]/a”;
字符串TableRowCount=“//*[@id='divContentHolder']/div[2]/table[%s]/tbody/tr[2]/td/table/tbody/tr”;
字符串viewcharrier=“//*[@id='divContentHolder']/div[2]/table[%s]/tbody/tr[2]/td/table/tbody/tr[%s]/td[3]”;
String ClaimPayer=“//*[@id='divContentHolder']/div[2]/table[%s]/tbody/tr[2]/td/table/tbody/tr[%s]/td[4]”;
Select WebList=newselect(driver.findElement(By.xpath(“/*[@id='ddlSelectUser']”));
List userlist=WebList.getOptions();
int usercnt=userlist.size();
System.out.println(usercnt);
String[]linktext=新字符串[usercnt];
int i=0;
for(WebElement e:userlist)
{
linktext[i]=e.getText();
i++;
}
对于(int-usrcnt=0;usrcnt/
>一些代码
> /
}
}
}

据我所知,selectByIndex您需要使用整数,但在代码中usrcnt似乎是一个问题。可能这就是问题所在。您可能可以使用selectByVisibleTexthey vinay在for循环中移动select,修复了for的问题(int usrcnt=0;usrcntGuess在循环中使用i而不是文本。但是从逻辑上讲,selectByIndex将使用整数而不是sting值作为参数。在for loop之前,我正在计算下拉列表中的项数,其中我使用selectByIndex的字符串值Select WebList1=new Select(driver.findelelement(By.xpath(“/*[@id='ddlSelectUser']));List userlist=WebList1.getOptions();int usercnt=userlist.size();for(int-usrcnt=0;usrcntHi-Patil)-当您有额外的信息时,最好编辑您的问题以将其包含在其中。这比将其作为响应发布更具可读性。