3

I have, in part, the following html structure:

[other menu buttons]
<a class="yuimenubaritemlabel yuimenubaritemlabel-hassubmenu" onclick="javascript:navigateTo('[redacted]');">ORDER CENTER</a>
[other menu buttons]
<iframe id="foo">
    <input type="text" id="sizeTextbox">
    <a id="bttnSubmitSearchBySize" class="bttnSubmitProductSearchBySize"></a>
    [snip other controls]
</iframe>

And the following code in my PageObject to handle it:

driver.switchTo().frame(foo);
//Search
sizeTextbox.sendKeys(size);
bttnSubmitSearchBySize.click();
[snip WebDriverWait for the search results to appear]
driver.switchTo().defaultContent();

where foo, sizeTextbox, and bttnSubmitSearchBySize are all WebElements lazy-loaded via PageObject.

The first time I perform the search in my test, everything works great. I enter a size, I click search, I find the row, I toggle a checkbox in it. I then go off to another page to verify that the checkbox changed the state of the product. I then come back to this page and, in theory, perform the same search, toggle the checkbox, and go off to verify that the product changed state again.

However, the second time I try to click bttnSubmitSearchBySize, instead, the Order Center button is clicked, and I am taken to the Order Center page. Furthermore, it seems to either be clicked multiple times or be hovered over, as there's a dropdown menu that appears on hover and it toggles on and off repeatedly until the test finally dies. This happens even if I recreate the PageObject to force it to re-find the button, and even if I manually re-find the button just before clicking.

What am I doing wrong?

Update: I've narrowed down the code responsible. The following snippit will also trigger the issue:

page.navigateTo();
page.searchBySize(size);
driver.navigate().refresh();
page.searchBySize(size);

(where searchBySize is the method containing the above search code).

So far nothing I've put after the refresh will prevent the bug; I've tried re-calling initElements and making a new instance of the pageObject both.

ETA: Today I discovered that this only happens in IE, specifically IE10, it does not happen in Chrome. I have therefore performed the following troubleshooting steps:

  • Verified that zoom is at 100%
  • Tried maximizing the window. No change.
  • Printed the location and size of the element. It's identical on both passes, but only the first succeeds.

3 Answers 3

0

Have you tried finding element again right before you click it, instead of lazy loading it? I don't know how lazy loading works, but it seems the element stored in bttnSubmitSearchBySize is not the element you want.

 bttnSubmitSearchBySize = driver.FindElement(By.Id("bttnSubmitSearchBySize"));
 bttnSubmitSearchBySize.click();
2
  • In theory, lazy loading does this, in that it does a find the first time the element is used. But I'll try doing it explicitly. Commented Oct 28, 2014 at 17:58
  • Nope, same result. Commented Oct 28, 2014 at 18:01
0

InternetExplorerDriver has had issues in the past with getting coordinates inside frames; the issue I found claimed to be resolved, but for a simpler use case, whereas my page uses a lot of frames.

A workaround that clicks more reliably:

    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", bttnSubmitSearchBySize);
0

I've worked with applications that have multiple components, but start looking funny and behaving oddly when you cross sessions in the same browser instance. This is likely because the developer reused code, which is a good practice wherever possible.

I would close the browser and then re-open it, get the url and continue in case this is what's happening to you.

    driver.quit();
    //ignore my external method for driver management, just restart your browser instance
    PublicDesktopDriverConfig pDDC = new PublicDesktopDriverConfig();
    driver = pDDC.DriverType(driver);
    //configure your browser settings and timeouts  
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    //get the url and continue
    driver.get("url");

Hopefully this helps.

In the event that it's something the developer had to do that makes objects load at different paces, sometimes needing to support something like an older version of IE, sleep should do it

    Thread.sleep(3000);

Something of that nature.

I have a custom driver manager called PublicDesktopDriverConfig, but you get the idea. Don't let that confuse you.

1
  • After you switch to default content, are you selecting the main frame to manipulate the results? I'm just checking, because I didn't see that in your example.
    – user8884
    Commented May 12, 2015 at 22:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.