Not able to click on the stored element | Selenium Forum
M
Posted on 11/02/2016
I tried to store a ID of element in a string then use it to click on it.

But Its not navigating to the page I am trying.

Here is my code:


List<WebElement> Content = driver.findElements(By.xpath("//*[@id='content-epic_badge']//a"));

System.out.println("Total values in Badge panel is " + Content.size());
// storing id in a string
String x = Content.get(0).getAttribute("id");
System.out.println("id of the CTA button " + x);
// using id to click on the link
driver.findElement(By.id(y)).click();


I am able to print the id which I searched for. But I am not able to use it to locate element. Is there anything wrong?

Thanks in Advance

M
Replied on 11/02/2016

You are fetching the id in String x, but while clicking you are passing String y.