Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Selenium 为什么我找不到元素错误?_Selenium_Selenium Webdriver - Fatal编程技术网

Selenium 为什么我找不到元素错误?

Selenium 为什么我找不到元素错误?,selenium,selenium-webdriver,Selenium,Selenium Webdriver,我将Xpath分为4个部分,因为在Xpath中,只有一行值发生变化,即/tr[2],如3,4,5直到路径结束 public class NewTest { @Test public void f() throws InterruptedException { System.setProperty("webdriver.chrome.driver", "F:\\New folder\\chromedriver.exe"); WebDri

我将Xpath分为4个部分,因为在Xpath中,只有一行值发生变化,即
/tr[2]
,如3,4,5直到路径结束

public class NewTest {

    @Test
    public void f() throws InterruptedException 
    {
        System.setProperty("webdriver.chrome.driver", "F:\\New folder\\chromedriver.exe");

        WebDriver driver = new ChromeDriver();

        driver.get("http://xxxxxxxxxxx/index.aspx");

        driver.manage().window().maximize();

        WebElement ee= driver.findElement(By.id("ddlstore"));
        Select s11 = new Select(ee);
        s11.selectByVisibleText("xxxxxx");

        String s1 = "/html[1]/body[1]/form[1]/div[5]/center[1]";

        String s2 = "/div[1]/table[1]/tbody[1]/tr[";

        String s3 ="]";

        String s4 = "/td[11]/input[1]";

        for(int i=2;i<=99;i++)
        {
            String finalXpath= s1+s2+i+s3+s4;

            driver.findElement(By.xpath(finalXpath)).click();

            Thread.sleep(3000);

            try {
                WebElement e1 = driver.findElement(By
                        .xpath("//p[@id='skipcount']"));
                System.out.println(e1.getText());

                WebElement e2 = driver.findElement(By.xpath("/html/body/div[1]/div/div"));
                WebElement e3 = driver.findElement(By.xpath("/html/body/div[1]/div/div/div[3]/button[2]"));
                Actions a1 = new Actions(driver);
                a1.moveToElement(e2).click(e3).build().perform();

            } catch (Exception e) {
                System.out.println("Can't Click on The Element ");
            }
        }
Try/Catch块中Xpath的Html代码:

<input type="submit" name="CustomPaging_GridView$ctl02$ff" value="SKIP" onclick="product_skip(this);" id="CustomPaging_GridView_ff_0" class="button2" data-id="12691247570" data-id1="36025">
<div class="modal-footer">
    <span id="prcid" style="display:none;">processing...</span>
    <button type="button" id="skipok" onclick="skipoverall(this)" class="btn btn-primary" data-id="12691247570" data-id1="36025">Ok</button>
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
</div>

处理。。。
好啊
取消
Ps:实际上,问题是,我需要单击一个“跳过”按钮,该按钮具有相同的Xpath For All按钮,每次单击“跳过”按钮时,都会出现一个弹出窗口,我需要单击“取消”按钮

int i = 1;

 String s2 = "/div[1]/table[1]/tbody[1]/tr[' " +i+ " '];
不需要字符串s3。

尝试以下操作:

// you don't need 'e2', instead you hover 'e3' and click on it
WebElement e3 = driver.findElement(By.xpath("/html/body/div[1]/div/div/div[3]/button[2]"));
Actions a1 = new Actions(driver);
a1.moveToElement(e3).click(e3).build().perform();
建议:

    String s1 = "/html[1]/body[1]/form[1]/div[5]/center[1]";

    String s2 = "/div[1]/table[1]/tbody[1]/tr[";

    String s3 ="]";

    String s4 = "/td[11]/input[1]";

    for(int i=2;i<=99;i++)
    {
        String finalXpath= s1+s2+i+s3+s4;
String s1=“/html[1]/body[1]/form[1]/div[5]/center[1]”;
字符串s2=“/div[1]/table[1]/tbody[1]/tr[”;
字符串s3=“]”;
字符串s4=“/td[11]/input[1]”;

对于(int i=2;i),该行抛出一个错误:无法定位元素,Xpath?表中有多少行?
for(int i=2;i<=99;i++)
    {
        String finalXpath= "/html[1]/body[1]/form[1]/div[5]/center[1]/div[1]/table[1]/tbody[1]/tr[" + i + "]/td[11]/input[1]";
        ...