1
driver.findElement(By.xpath("xxxx")).click();

Clicking on the above link will take to another page. But it will take long time. So while trying to find an element in the resulting page shows an error.

driver.findElement(By.xpath("yy")).getText();

I have tried Implicit and Explicit Waits, but it is not working everytime.

kripindas
  • 480
  • 2
  • 7
  • 21

1 Answers1

0

Use WebDriver wait. Put element which you need in 2nd page. Feel free to change any locator in below code :-

WebDriverWait wait = new WebDriverWait(driver, 100);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));

Hope it will help you :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • @shubam jain I have tried the webDriverWait method, but it is not woking everytime I run the code. When the load becomes maximum in the website, the test case fails, because it is not finding the element after loading the page. – kripindas Sep 30 '15 at 12:06
  • Shumbham Jain's solution looks good. Perhaps try increasing the waiting period. – Rameshwar Sep 30 '15 at 12:19
  • @Rameshwar -> Thanks :) .. @kripindas-> please try to increase waiting period as Rameshwar said.. there is one more probability.. Is your 2nd page opening in a new tab... If Yes then you also have to switch to that page. for that you can refer :- http://stackoverflow.com/questions/9588827/webdriver-switch-to-new-browser-opened-after-click-on-button – Shubham Jain Sep 30 '15 at 12:41
  • If nothing works then use Thread.sleep(100000); .. But I want to tell you that is not a good practice to use that – Shubham Jain Sep 30 '15 at 12:43