Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.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,查找web元素的相对xpath_Java_Html_Selenium_Xpath - Fatal编程技术网

Java,查找web元素的相对xpath

Java,查找web元素的相对xpath,java,html,selenium,xpath,Java,Html,Selenium,Xpath,我试图浏览一个表id=ActivationAllAvailableList,并迭代浏览一个标题列表: xpath=./*[@id='ActivationAllAvailableList']/li/div/div/h3以查看它是否与我想要的匹配 如果是,则单击相应的按钮: xpath=./*[@id='ActivationAllAvailableList']/li/div/div[3]/a 十一月竞选元标题 qwe 插入一个中断;单击要从循环中转义的元素后。见下文: public void cl

我试图浏览一个表id=ActivationAllAvailableList,并迭代浏览一个标题列表: xpath=./*[@id='ActivationAllAvailableList']/li/div/div/h3以查看它是否与我想要的匹配

如果是,则单击相应的按钮:

xpath=./*[@id='ActivationAllAvailableList']/li/div/div[3]/a

十一月竞选元标题 qwe 插入一个中断;单击要从循环中转义的元素后。见下文:

public void clickSpecificGetStartedButton(String metadataTitle)
{
for (WebElement el : campaignTable)
{
    WebElement metadataTitleTextElement = el.findElement(By.xpath(".//div/h3"));
    if (metadataTitle == metadataTitleTextElement.getText())
    {
        WebElement getStartedButton = el.findElement(By.xpath(".//div[3]/a"));
            getStartedButton.click();
            break;
        }
    }
}
}

我修复了它,但我仍然不确定为什么原始代码不能工作

List<WebElement> campaignTable = driver.findElements(By.xpath(".//*[@id='campaignAllAvailableList']/li/div"));  
for (WebElement el : campaignTable)
{
    String metadataTitle = el.findElement(By.xpath(".//div/h3")).getText();

    if (target.compareTo(metadataTitle)==0)
    {
        WebElement getStartedButton = el.findElement(By.xpath(".//div[3]/a"));
        getStartedButton.click();
        break;
    }
}``

问题到底是什么?有错误吗?我只是在帖子中包含了错误-对于WebElement el:campaignTable,它失败了,我认为它没有正确地将campaignTable作为列表来阅读。请在问题中发布相关的HTML,而不是使用图像。图像最终将无法访问,然后这个问题将变得不那么有用。它在“for WebElement el:campaignTable”行失败,因此中断并没有真正起到帮助作用,因为FindByxpath=./*[@id='campaignAllAvailableList']/li/divis不起作用,而您添加了中断