0

I want to click a href link, then go back to previous page, then click next href link which has text "Meer info".

I wrote following code, but it is producing an Exception. I can go to web then click first link that I want to click with text name "Meer info" than go to back but then I want to click second linkText also with the same text name "Meer info" but I don't know how to do that.

WebDriver driver = new FirefoxDriver();
driver.get("http://turksegids.nl/index.php");
Thread.sleep(3000);
driver.findElement(By.cssSelector("input[type='image'][value='Zoek!']")).click();
Thread.sleep(5000);
driver.findElement(By.linkText("Meer info")).click();
Thread.sleep(4000);
driver.findElement(By.linkText("Terug naar de resultatenpagina")).click();
Thread.sleep(8000);
driver.findElement(By.linkText("//a[text()=\"Meer info\"]/following- 
sibling::a[2]")).click();

Thread.sleep(4000);
driver.close();
driver.quit();

I am getting this Exception

Unable to locate element: {"method":"link text","selector":"//a[text()=\"Meer info\"]/following-sibling::a[2]"}
1
  • Hi Muratcan, your entire script seems to be wrong; let me send you the right one shortly Commented Feb 18, 2014 at 11:38

2 Answers 2

1

You can use below code:

WebDriver driver = new FirefoxDriver();
driver.get("http://turksegids.nl/index.php");
driver.findElement(By.cssSelector("input[type='image'][value='Zoek!']")).click();
driver.findElement(By.linkText("Meer info")).click();
driver.findElement(By.linkText("Terug naar de resultatenpagina")).click();
driver.findElement(By.xpath("//*[@id='resultatenklik_28957_info']/u")).click();
driver.close();
driver.quit();

and see it works or not

Sign up to request clarification or add additional context in comments.

Comments

1

Try to use

List<WebElement> element = driver.findElements(By.linkText("Meer info"));
element.get(2).click();

instead of

driver.findElement(By.linkText("//a[text()=\"Meer info\"]/following- 
sibling::a[2]")).click();

It will work !!

1 Comment

let me know if you still face issues; I have alternate answers for you . Sams | seleniumworks.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.