Reputation: 57
I am trying to click an element by contains text
Here is my code
String bidname= dataTable.getCommonData(CommonDataColumn.BidName);
System.out.println(bidname);
driver.findElement(By.xpath("//a[contains(text(),bidname]")).click();
Actually I need to check from my excel sheet and then check the webpage if that text is present or not.
For example in my excel sheet my bid name are there, now I need to find if it is present on webpage and click on it.
Earlier I was hard coding it. But now I need to implement like above said.
Upvotes: 1
Views: 5293
Reputation: 12613
bidname
is a variable in your Java code. You need to append the value of bidname
to the XPath string. Try:
driver.findElement(By.xpath("//a[contains(text(),'" + bidname + "')]")).click();
Upvotes: 2