1

I have an issue with selenium webdriver and i would be very grateful if anyone can help me

Environment:

  • selenium-server-standalone-2.31.0.jar / selenium-server-standalone-2.35.0.jar
  • IEDriverServer.exe (tried version 2.28 - 2.35)

Sample code:

WebElement href = this.findElement(By.xpath("//A"));    
href.sendKeys(Keys.ENTER);
href.click();

Problem: A fix to any of this would help me

  1. href.sendKeys() successfully simulates user click, but does not wait for page to load
  2. href.click() fails to simulate user click, but successfully wait for page to load
  3. I have search for the source code of .click() method to try to manually create a waitForPageToLoad function, but i haven't been able to find it.

I know i am not giving to much information because the application I am running the test against is internal, so I cant share a link for debugging. But any idea or previous experience with similar problems that could help me figure out what is going on would be appreciate it.

Right now, I have to do both sendKeys and click to achieve the expected results.

Big Dude
  • 264
  • 1
  • 6
  • 25
Dazz
  • 13
  • 1
  • 1
  • 4
  • Can you share the error message? – Amey Sep 05 '13 at 22:56
  • Since you are clicking on the link why not use click method instead of send key? Any specific reason? – Vinay Sep 06 '13 at 01:45
  • You should apply wait condition after performing the click event i.e. after `href.sendKeys(Keys.ENTER);` refer different wait condition here http://stackoverflow.com/a/12859689/624003 – Sankumarsingh Sep 06 '13 at 04:49

2 Answers2

4

Whenever you do .click() on a button or link an internal method something like "waitTillPageLoads()" is called and hence webdriver waits until the next page is loaded completely.

I have experienced a scenario where it waited for almost 10-15 minutes for the page to load because web app was too slow. Wierd it sounds i know.

however sendKeys() doesn't wait. Because sendkeys is not used for clicking purpose rather it used for entering keys.

I guess there must be some strong reason for you to do

href.sendKeys(Keys.ENTER);

And if you still want to go with this approach you can implicitly you can wait for element of next page using implicit wait

WebDriverWait wait = new WebDriverWait(webDriver, 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath")));

Please note :

You quotation

href.click() fails to simulate user click, but successfully wait for page to load

Can be because you have not set your browser level to 100%.

Please Check my answer at Unable to run Selenium script on IE

Community
  • 1
  • 1
Abhishek Singh
  • 10,243
  • 22
  • 74
  • 108
  • This is the correct answer. I didnt have the browser level to 100% but I launched it with ignoreZoomSetting, so the app would run without issues, but wouldnt click the right position. Thank you very much – Dazz Sep 06 '13 at 15:13
  • Waiting for 10-15 minutes for a page to load is what i want to. I am using selenium to create a monitoring tool that measure response times and not only run tests. So the timeout of explicit and implicit waits doesnt suit my needs. Thanks again for the answer. – Dazz Sep 06 '13 at 15:25
1

What you can do here is after sendKeys operation, put several waits for elements which are on the resulting page using WebDriverWait. This will serve your purpose.

Pratik G
  • 99
  • 2