无法单击通过xpath中的变量传递的元素。变量属于另一类

时间:2016-02-12 10:52:23

标签: selenium xpath webdriver

WebDriverWait wait = new WebDriverWait(driver, 15);
         wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[contains(.,'"+eventname+"')])"))); 

        WebElement editeve = driver.findElement(By.xpath("//a[contains(.,'"+eventname+"')])"));
        //driver.findElement(By.xpath("//a[contains(.,'abc2016Feb11ab')]"));
        Actions actions = new Actions(driver);
        actions.moveToElement(editeve);
        actions.perform();
        editeve.click();

1 个答案:

答案 0 :(得分:0)

如果syso的值很好,那么创建一个字符串。首先连接xpath的所有值,然后将其传递给元素

String xpathOfEvent ="//a[contains(.,'"+eventname+"')])"; 
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathOfEvent)));

我假设您的定位器很好并且能够找到元素

希望它会对你有所帮助:)。