Reputation: 11251
I need to click "Databases" button. I try this code:
driver.switchTo().frame("frame_content");
wait.until(visibilityOfElementLocated(By.id("topmenucontainer")));
driver.findElement(By.linkText("server_databases.php?token=650c2ac770f7d54449d462b18ddd6a01"));
But even mention of current link don't help me, I have exception:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"partial link text","selector":"server_databases.php?token=65...
What I am doing wrong? How I can do it with XPath ore somehow else?
Upvotes: 0
Views: 364
Reputation: 1400
This will do it.
driver.findElement(By.xpath("//a[contains(@href,'server_databases.php?token=')]"));
or
driver.findElement(By.xpath("/html/body/div[2]/ul/li/a"));
Upvotes: 0
Reputation: 7008
As Richard has mentioned, you should mention the link text which is visible to the user ,i.e, link text which is displayed on the screen.I'm sure the above solutions worked but it is important to know why your code hasn't worked.
So replace,
driver.findElement(By.linkText("server_databases.php?token=650c2ac770f7d54449d462b18ddd6a01"));
with
driver.findElement(By.linkText("Databases"));
Upvotes: 0
Reputation: 1730
Try this:
driver.findElement(By.xpath("//a[contains(@href,'server_databases.php?token=')]"));
your token may be generated every time so let it find if contains partial of link.
Upvotes: 1
Reputation: 70
You appear to be using partial link text although that link does not appear to have any text. I think you want to use something like css selector and use the href attribute.
driver.findElementBy(By.cssSelector("[href*='server_databases.php?token=650c2ac770f7d54449d462b18ddd6a01']"))
Upvotes: 1
Reputation: 9019
Partial link text refers to the text between the <a ...></a>
tags. You're trying to match link text on href, not the link text itself.
Upvotes: 0