Anyone good at WebDriver?


  • I survived the hour long Uno hand

    I tried asking on sqa.stackExchange, but that place is a goddamn ghost town, so I'm sure to get better advice here even if nobody's ever used Webdriver before.

    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">
        [snip other controls]
        <input type="text" id="sizeTextbox">
        <a id="bttnSubmitSearchBySize" class="bttnSubmitProductSearchBySize"></a>
        [snip other controls]
    </iframe>
    

    TRWTF is that we haven't replaced YUI with JQuery on this page yet
    And the following code in my PageObject to handle it:

    driver.switchTo().frame(foo);
    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.

    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.

    What am I doing wrong?



  • I've used some webdriver, but I'm far from an expert.

    Silly question... do you actually see the browser while this is happening? If you're using headless, can you switch to a visible while debugging?

    That was the only way I ever managed to debug anything with web driver.


  • I survived the hour long Uno hand

    Yes, I can see it; I'm hitting a VM using RemoteWebDriver, but I've Remote Desktopped into the VM so I can watch. The dropdown menu under Order Center opens and closes rapidly even after navigating. Still can't figure out why it's going for that random menu button instead of the search button.



  • Strange. What happens if you remove the "ORDER CENTER" button?

    Also, can you extract some kind of reference or text representation of bttnSubmitSearchBySize before you click it?


  • I survived the hour long Uno hand

    New data point: This does not appear in chrome, only in IE. I'm using IE10.



  • Try replicating by hand. If your succeed, then it's IE bug. If not, then WebDriver bug.

    Either way, you'll have to fiddle with DOM or WebDriver code until it works. No smarter advice from me, I'm afraid.


  • I survived the hour long Uno hand

    @cartman82 said:

    Try replicating by hand

    How, exactly? I can click the correct button all day long and nothing weird happens. Webdriver is clearly clicking in the wrong spot.


  • I survived the hour long Uno hand

    @cartman82 said:

    can you extract some kind of reference or text representation

    That took rediculously long, something like 4 tries. It's definitely the right button each time though:

    <A class=bttnSubmitProductSearchBySize id=bttnSubmitSearchBySize></A>
    <A class=bttnSubmitProductSearchBySize id=bttnSubmitSearchBySize></A>
    

    I think my problem is in how it's clicking. I'm guessing in IE it's clicking by screen coordinates and somehow our DOM is confusing it into grabbing the wrong coordinates, and the Order Center button just happens to be where it thinks the search button is.



  • @Yamikuronue said:

    I think my problem is in how it's clicking. I'm guessing in IE it's clicking by screen coordinates and somehow our DOM is confusing it into grabbing the wrong coordinates, and the Order Center button just happens to be where it thinks the search button is.

    Ugh. Possibly. Not sure what to do about that? Temporarily hide all other elements during that part of the test? :-)

    @Yamikuronue said:

    How, exactly? I can click the correct button all day long and nothing weird happens. Webdriver is clearly clicking in the wrong spot.

    I was thinking, pause the web driver at that point and carefully examine the state of the DOM. Other variant, do personally all the things WB is doing and then examine.

    That's how I remember catching one of the bugs. But since in your case it seems to be WebDriver bug, seems less applicable.


  • I survived the hour long Uno hand

    @cartman82 said:

    Not sure what to do about that?

    Just ran down my "IE bug" checklist. The window is at 100%, no weird zoom levels; maximizing the window shows no change, and printing the location and size of the element proves no change between the first click and the second.


  • I survived the hour long Uno hand

    Urgh. This is probably related to https://code.google.com/p/selenium/issues/detail?id=3614 (which is fixed, but maybe not in all use cases. We use a LOT of frames. This site is slated to be replaced altogether next year).


  • I survived the hour long Uno hand

    A WORKAROUND HAS BEEN LOCATED!!!

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

    Fuck IE.



  • OH YES!

    Great idea, filed away in case I stumble upon this shit.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.