使用动态文本定位元素

时间:2015-06-03 07:07:54

标签: selenium webdriver testng

任何人都可以帮我创建动态文本的定位器 这里0是dynmaic,可以在每次执行测试脚本时更改。

<a
 title="mytest" href="/abc/test/page1">0  
</a>

这里0是动态的,可以为不同的用户进行更改。我使用excel的数据驱动方法来获取输入。

由于

2 个答案:

答案 0 :(得分:0)

WebElement yourElement = driver.findElement(By.xpath("//a[contains(@title, 'mytest')]"));

答案 1 :(得分:0)

您可以使用以下代码:

WebElement yourElement = driver.FindElement(By.Xpath(String.format("//a[contains(@title, 'mytest') and text()='{0}']", yourText)));

按标题查找元素+传递给string.Format方法的动态文本。

相关问题