Search code examples
rubyseleniumwatir

Select() method and option() method works differently


Today I have seen a question in selenium C# section where this question was posted, I try to solve that problem through WATIR coding, I have written the below code and WATIR identifies this select list as invisible.

b.goto 'http://automationpractice.com/index.php'
b.img(title: 'Faded Short Sleeve T-shirts').click
b.iframe(xpath: "//*[starts-with(@id,'fancybox-frame')]").select_list.select("L")

But If I select that same select_list through below metioned code, it works fine.

b.iframe(xpath: "//*[starts-with(@id,'fancybox-frame')]").select_list.option(text: "L").click

I don't understand what is the difference here, when I put a debug pointer, both are making a selenium call to find_element(tag_name: "select"), first one fails due to element invisible but second one passes

@Titus, @JustinKo Can you please explain me what's happening here? what's the difference?

Note: Please run it in Chrome.


Solution

  • Moving from a comment to an answer:

    The issue is that we refactored the normal (non-select-list) way of doing it to not check for whether an element is displayed ahead of time, and put the waiting logic in the rescue block if Selenium complained. The select-list code is still checking the visibility ahead of time, and this particular select-list element is not displayed according to Selenium. Since it appears that Selenium can select options without select list showing as displayed, Watir should not be waiting for this.

    I've fixed it here, and it will be working in Watir 6.13 (should be released "soon")

    https://github.com/watir/watir/commit/77af164fcdecb71d8d2240110d3fb4b1dabeee4b