Ruby Selenium/Watir ".select" does not do anything in Safari (any version) - ruby

I'm having a painful time trying to select a value in a select field in Safari. It works fine in Chrome, Firefox and IE.
It finds the object fine, but it doesn't select any value. It also doesn't return any error.
I've also tried this on multiple websites with select fields (same issue):
launch browser
browser = Watir::Browser.new :safari, url: "http://localhost:4444/wd/hub"
Set object (works fine)
elTitle = #browser.element(xpath:'//select[#name="ddTitle"]')
Now things i've tried to select the value:
elTitle.option(:text => "Mrs").select
above returns nil, and nothing actually selected
also tried:
elTitle.options[1].click
above returns nil, and nothing actually selected
also tried:
elTitle.send_keys "Mrs", :tab
(which often results in the listbox options displayed (with the correct value with a tick next to it), but it's on top of the browser and prevents any further code from continuing - but this is another issue altogether)
Ruby: 2.2.6
safari v11.0.3 (High Sierra)
watir gem: 6.10.3
selenium-webdriver: 3.9.0
selenium-standalone-server: 3.9.1
Originally had older versions of these gems, which had the same issue, so updated them, and still have the issue. Had also tried with earlier version of Safari (v10/Sierra), which had the same issue.
I've also been unable to launch Safari Technology Preview (but this is an issue i'll raise separately)
So, in summary, has anyone been able to do ".select" on a select field in Safari?

YOu are doing it wrong, you are calling option method for wrong object.
Try this syntax for select_list always
b.select_list(name: "ddTitle").select "Mrs"
Other syntax is
b.select_list(name: "ddTitle").option(text: "Mrs").select
option method has to be called for Watir::Select object not for Watir::HTMLElement, you are actually calling for Watir::HTMLElement, so it's not working.

Related

Firefox Dev Edition: shorter XPATH finder

how is it possible to easily obtain short form of XPATH through Inspector?
For example, if I try "Copy xpath" on web element I get pretty long response like this:
/html/body/div[6]/div[1]/div[1]/p[13]
Instead of this or similar:
//[#id='exeample_value']*
Since I need to cover a lot of these, do not want to loose time to shorten them manually. In older versions of Firefox I used plugins like Firebug and Firepath, but they seem not to be compatible with new FF versions (and FF Dev Edition).
The Firefox DevTools don't allow to copy relative XPaths yet (as of Firefox 58). Therefore I've filed bug 1410810 for it some time ago.

Firefox "Mouseover" issues in Selenium Ruby bindings on Windows

I've been struggling with mouse hover for a couple of days and found a couple of threads here on the topic, but none have helped. I've tried dozens of different approaches and have also modified my code to be more in sync with the examples here, especially Dave Haeffner's suggestions. The current code looks like:
Selenium::WebDriver::Wait.new(timeout: 2).until do
#driver.find_element(link: "ADMIN").displayed?
end
#driver.action.move_to(#driver.find_element(link: "ADMIN")).perform
Selenium::WebDriver::Wait.new(timeout: 2).until do
#driver.find_element(link: "ORGANIZATION").displayed?
end
driver.action.move_to(#driver.find_element(link: "ORGANIZATION")).perform
Selenium::WebDriver::Wait.new(timeout: 2).until do
#driver.find_element(link: "TEAMS").displayed?
end
#driver.find_element(link: "TEAMS").click
end
On macs, this code works fine. On Windows however, it produces:
Failure/Error: #driver.action.move_to(#driver.find_element(link: "ADMIN")).perform
Selenium::WebDriver::Error::InvalidElementStateError:
Cannot perform native interaction: Could not load native events component.
I'm sure the element access is fine, because if I change the first mouse hover to a click action, it works great.
Any help would be appreciated.
You need to use Firefox version 31.0.6 . Versions of Firefox after that don't have the native events support. If you need to use a later version of Firefox, then just make sure your test actions are all non-native, such as using a JavascriptExecutor to create a hover (instead of relying on native events in the firefox driver).

Test success differences in different browsers

When attempting to click elements using a CSS selector, e.g
browser.find_element(:css, '.login').click
I am seeing different behaviours in different browsers. This is the behaviour I am seeing:
Chrome (35.0.1916.114) - works as expected
Firefox (24.0) - seems to ignore the command and move onto the next line of the test. Either that or it thinks it has clicked the element when it has not.
Safari (7.0.3 (9537.75.14) - complains that the element is not present. Interestingly, this one doesn't even seem to wait until the page has even loaded.
I have tried using a variety of web driver versions (2.42.0, 2.39.0, 2.33.0) and different browser versions with no success.
It turns out that my specific problem was that Firefox doesn't like targeting link elements inside lists, whilst chrome will do it fine. For example:
The following will not work in Firefox:
Browser.find_element(:css, '.list-item')
Whereas this will:
Browser.find_element(:css, '.list-item > a')
This may have been a unique problem for the site I was testing, but it is worth bearing in mind.

console.log is not working when used in a Firefox, Greasemonkey script

My userscript prints some information using console.log().
This works fine in Chrome, but when I install this userscript in Firefox (Greasemonkey), the web console in Firefox is not displaying anything.
I searched for a solution and some suggested to use unsafeWindow but it is also not showing any output. Moreover unsafeWindow cannot be used for chrome. I even installed Firebug but it was no use. How can I resolve this?
For example, I tried this userscript in Firefox:
// ==UserScript==
// #name console
// ==UserScript==
console.log("hello");
You mean it doesn't work when installed via Greasemonkey, right?
Not long ago, Greasemonkey broke console.log (New! Bug report). Now, to see the results of a plain console.log() call from a Greasemonkey, you need to look in Firefox's Error console, not Firebug's.
You can see FF's Error console by pressing: CtrlShiftJ.
However, you can use unsafeWindow.console.log() in both Chrome and Greasemonkey scripts. Chrome now has limited support for unsafeWindow.
If you use unsafeWindow, you have access to the full range of Firebug's logging functions from Greasemonkey. (Firebug must be installed and they still might not work in Chrome userscripts; I haven't tested that way in a while.)
In Firefox, if Firebug is not installed, or it is not active for the page, then unsafeWindow.console.log() calls will display to the New "Web Console" (CtrlShiftK).
You need to use the unsafeWindow when inside a Greasemonkey script.
Note that Firefox currently supports console.log(), console.info(), console.warn(), and console.error() natively -- no Firebug required.
Wait a minute: if the question is about logging in the console with Greasemonkey (I could swear I saw the tag greasemonkey), why not use the GM_log method?
// ==UserScript==
// #name GM_log Example
// #namespace http://www.example.com/
// ==/UserScript==
GM_log("This is an example of GM_log");
Or am I missing something?
PS: you can also check for javascript.options.showInConsole in about:config. it should be true.
I found that (testing with Chrome/Tampermonkey) you need:
window.log("<message goes here>");, not unsafeWindow.console.log("<msg>");,
as unsafeWindow and console come up as undefined.
Try that, as I'm pretty sure that's the way you're supposed to do it in later versions of browsers, etc.

Watin support for IE 9 - Part 2 (Specific)

Watin Runtime Version: v2.0.50727
Browser: IE 9
I have found a specific issue:
BaseIEController.IE.Element(fieldname).Exists throws an Exception as under:
"It's not possible to find the element because no element finder is available."
The fieldname here is a Regex for a link, a simple Regex where the Link's Id is passed.
This works with IE 8.
I cannot use the Final Release of Watin 2.0 since the LogonHandler is not complete (not fully functional as mentioned in the Release Document. I have tried testing it as well).
Any idea on how I can get this Element thingy to work??
Thanks,
K
Today I have upgraded to IE9 on my windows 2008 system and run all the 745 WatiN 2.x unittests and found no issues (accept for one dialog handling the javascript::return dialog fired by onbeforeunload event).
Let me know if you have more specific info/ code example will help too to reproduce the issue you reported.
Jeroen
Lead dev WatiN
Thank you for the response. Firstly, Awesome job with Watin :)
I am trying to run the test using VS2008 and IE 9. The goal is to Click a Link but before that I am verifying if the Link is exists.
The Regex I use for this link is LnkSignIn = new Regex(".*linkSignIn$");
I then use BaseIEController.IE.Element(fieldname).Exists where the fieldname is an Attribute Constraint (in this case the Regex). This would return a true or false if the Link is found. If found, I then click the Link. Instead it returns the Error MyTestInitialize threw exception. WatiN.Core.Exceptions.WatiNException: WatiN.Core.Exceptions.WatiNException: It's not possible to find the element because no element finder is available.. at WatiN.Core.Element.WaitUntilExistsOrNot(Int32 timeout, Boolean waitUntilExists)
...
This works just fine with IE 8. Further, I noticed that if I change Element to Link, it returns true. But since this is a generic method, I want to keep it as element. Hope this helps. Please let me know if you need more information. Thanks.

Resources