selenium 2.0是否支持By.xpath的动态字符串值

时间:2011-05-24 00:38:25

标签: webdriver selenium-webdriver

我正在尝试使用以下代码点击复选框:

String podID =“'microsoft-gallery-clipbox-pod-”+ podId.substring(3)+“'”;

  driver.findElement(By.xpath("id(" + podID + ")")).click();

org.openqa.selenium.NoSuchElementException:无法找到元素:{“method”:“xpath”,“selector”:“id('microsoft-gallery-clipbox-pod-15423100')”} 系统信息:os.name:'Windows 7',os.arch:'x86',os.vers

当我运行以下代码时,它可以正常工作:

driver.findElement(By.xpath( “ID( '微软画廊-影片箱-POD-15424100')”))点击();

知道为什么第一个代码无效?

2 个答案:

答案 0 :(得分:0)

您显示的两个ID不相同(末尾的数字不同):

microsoft-gallery-clipbox-pod-15423100

microsoft-gallery-clipbox-pod-15424100

这可能是问题吗?

答案 1 :(得分:0)

我会尝试使用以下内容:

String podID = "microsoft-gallery-clipbox-pod-" + podId.substring(3); 
driver.findElement(By.xpath("//*[@id='" + podID + "']")).click();