selenium-webdriver error for just opening IE - cucumber

So, I am using -
gem 'watir-webdriver', '0.5.4'
gem 'selenium-webdriver', '2.21.1'
and JRuby - 1.6.5
All I am trying to do is open IE. I have IE version 8.
>> require "rubygems"
=> true
?> require "watir-webdriver"
=> true
?> #b = Watir::Browser.new :ie
Selenium::WebDriver::Error::UnhandledAlertError: Modal dialog present
from C:/jruby-1.6.5/lib/ruby/gems/1.8/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'
from C:/jruby-1.6.5/lib/ruby/gems/1.8/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
from C:/jruby-1.6.5/lib/ruby/gems/1.8/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
from C:/jruby-1.6.5/lib/ruby/gems/1.8/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/remote/http/default.rb:64:in `request'
from C:/jruby-1.6.5/lib/ruby/gems/1.8/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/remote/http/default.rb:62:in `request'
from C:/jruby-1.6.5/lib/ruby/gems/1.8/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from C:/jruby-1.6.5/lib/ruby/gems/1.8/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/remote/bridge.rb:598:in `raw_execute'
from C:/jruby-1.6.5/lib/ruby/gems/1.8/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/remote/bridge.rb:92:in `create_session'
from C:/jruby-1.6.5/lib/ruby/gems/1.8/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/remote/bridge.rb:68:in `initialize'
from C:/jruby-1.6.5/lib/ruby/gems/1.8/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/ie/bridge.rb:40:in `initialize'
from C:/jruby-1.6.5/lib/ruby/gems/1.8/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/common/driver.rb:35:in `for'
from C:/jruby-1.6.5/lib/ruby/gems/1.8/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver.rb:63:in `for'
from C:/jruby-1.6.5/lib/ruby/gems/1.8/gems/watir-webdriver-0.5.8/lib/watir-webdriver/browser.rb:35:in `initialize'
from (irb):5:in `evaluate'
from C:/jruby-1.6.5/lib/ruby/1.8/irb.rb:158:in `eval_input'
from C:/jruby-1.6.5/lib/ruby/1.8/irb.rb:271:in `signal_status'
from C:/jruby-1.6.5/lib/ruby/1.8/irb.rb:155:in `eval_input'
from C:/jruby-1.6.5/lib/ruby/1.8/irb.rb:154:in `eval_input'
from C:/jruby-1.6.5/lib/ruby/1.8/irb.rb:71:in `start'
from C:/jruby-1.6.5/lib/ruby/1.8/irb.rb:70:in `catch'
from C:/jruby-1.6.5/lib/ruby/1.8/irb.rb:70:in `start'
from C:/jruby-1.6.5/bin/jirb:13:in `(root)'
from -e:1:in `load'
from -e:1:in `(root)'>>
IE webdriver gets opened, but above error comes.
When I use any other browser - firefox or chrome - they just open as they were supposed to open. It started happen just from this week. I mean I am using selenium-webdriver for years now and never had a problem opening IE or any browser. Error says there is a modal dialog box, but how can there be a modal dialog box when I just open IE, and I don't see any dialog when IE webdriver opens up. And if so, why other browsers don't complain?
I am assuming it might need to do with some windows or security updates that gets pushed on company laptop, but I just want to see if someone else have encountered this before and what was the solution?

There are two possibilities I can think of. One is that you have the Windows Task Manager open when you're trying to execute your tests. There is a bug in previous versions of the IE driver that could improperly throw the UnexpectedAlertException if the Task Manager were open while running code with the IE driver.
The second option is a browser plugin that internally creates a dialog window, but keeps it hidden. There are a number of antivirus and other anti-malware plugins for IE that may cause the issue.
In either case, update to a later version of IEDriverServer.exe to see if that solves the problem.

okay, found a solution. It was anti-virus thingy. The issue was - when you are running script with IE the McAfee site adviser modal window is sitting on top of IE browser so we can not get to IE browser to even open it. and it was specific to IE only because IE being 'default' and 'preferred' browser in my workplace.
McAfee supplied two dll files and copy-pasting them to some specific location solved the issue. Sorry, I used all of your minds in this question while it was not related to selenium but was mcafee issue. Closing the question.

Related

How to close facebook's chatbox in Watir

I'm currently struggling atm on closing facebook's chatbox whenever my program goes to a page's page (intended kek). It pops up after a few secs upon page load completion. I cant seem to access elements inside it even if its already loaded specifically the "x button" at the top right as long as the chatbox has focus (header is blue).
#b.a(href: "https://www.facebook.com/"+handle+"/?ref=br_rs").click()
#b.a(aria_label: "Close tab").wait_until_present.click()
Running the 2nd line returns a timeout error even though Im staring straight at it for 30secs. Magically (at least for me) the 2nd line runs if the chatbox loses focus (turns gray, mostly when i tab out). I've tried setting focus on some of the main page's element but to no avail. I can also close it if i do a send_keys but It requires me to add a sleep for like 3 seconds or so till the chatbox automatically opens upon page load but I heard adding hard coded sleep is not recommended. Any help? Thanks in advance.
Tried this and it worked on Windows 10, watir 6.12, chromedriver 2.41, Chrome 68.0.3
b.a(:'aria-label' => 'Close tab').click
For some reason it did not on my other machine, Ubuntu 16.04, Watir 6.11, chromedriver 2.40, Chrome 67.0.3
It magically worked after this
require 'watir'
p = Selenium::WebDriver::Chrome::Profile.new
p['enable_aria_label'] = true
b = Watir::Browser.new :chrome, :profile => p
sleep 40 #logged in manually and opened chat box
b.a(:'aria-label' => 'Close tab').click
sleep 20
It closes first chat box it finds. You can close specific one via
b.as(:'aria-label' => 'Close tab')[0].click
Maybe it will work for you too.

watir - is it able to use watir-webdriver and selenium-webdriver in the same time?

I'm new to automation, sorry if the title is not appropiate.
I have Ruby, Devkit, gem json, cucumber, capybara, selenium-webdriver, rspec installed following the guide http://www.swtestacademy.com/ruby-cucumber-and-capybara-on-windows/
However I cannot locate an element using a full xpath (checked and verified with xpath plugin and developer tool), my action is:
page.find(:xpath, "my_xpath").send_keys(yyy)
and I got:
Unable to find visible xpath
I also tried:
page.findElement(By.xpath("my_xpath")).send_keys("ori_pw")
and I got:
uninitialized constant By (NameError)
And I would like to try using watir, I have installed gem watir, watir-webdriver.
and added require 'watir' into my env.rb
then I try:
page.input(:name => "xxx").set(yyy)
But I get: undefined method `input' for # (NoMethodError)
May I have some suggestions please?
Thanks.
=============================================Edit#1
My env.rb now looks like this:
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'rspec'
require "selenium-webdriver"
require 'watir'
require 'cucumber'
Selenium::WebDriver::Firefox::Binary.path='C:\Program Files\Mozilla Firefox\firefox.exe'
Capybara.run_server = false
#Set default driver as Selenium
Capybara.default_driver = :selenium
#Set default selector as css
Capybara.default_selector = :cs
#Syncronization related settings
module Helpers
def without_resynchronize
    page.driver.options[:resynchronize] = false
    yield
    page.driver.options[:resynchronize] = true
end
end
World(Capybara::DSL, Helpers)
How can I disable capybara and set watir properly?
Sorry that I have no technical background...
Thomas, Yes the element is visible,
HTML screenshot
Actually I will be setting value to these 3 password fields.
The xpath I'm trying is:
/html/body[#class='modal-open']/app-root/div[#id='wrapper']/app-navigation/user-change-password/div[#id='myModal']/div[#class='modal-dialog modal-lg']/div[#class='modal-content']/div[#class='modal-body']/form[#class='ng-pristine ng-invalid ng-touched']/fieldset[#class='form-horizontal']/div[#class='form-group'][1]/div[#class='col-sm-7']/input[1]
(at the end I use avoid using class as I see the class name different sometimes)
Thanks.
=============================================Edit#2
The problem now shift to chromedriver.
Double clicking it able to show
Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 9515
Only local connections are allowed.
But enter chromedriver on cmd will show Chromedriver.exe has stopped working.
The reason it's not working for you is due to an unfortunate bug in geckodriver/firefox - which is probably also going to affect watir - whereby it assumes any element with a hidden attribute is actually non-visible (if the display style is set to anything other than default it actually overrides the hidden attribute but not as far as selenium is concerned). This is affecting you because of the hidden attribute on the element div#myModal which makes selenium think the entire modal is non-visible - https://github.com/mozilla/geckodriver/issues/864. If you swap to testing with Chrome instead the issue will go away.
Additionally using XPaths as specific as you show is a terrible idea and will lead to highly fragile tests. If you swap to Chrome (Capybara.default_driver = :selenium_chrome) you'd be much better off just doing something like
page.fill_in('Original Password', with: 'blah')
or
page.find('input[name="originalPassword"]`).set('blah')
One final point, the :resynchronize option went away a long time ago, you might want to find a more up to date guide to follow

MAC OS X difference between "open APP.app" and "APP.app/content/MacOs/APP" shell scripts

Somehow I get a problem, if I call an application twice or several times but only one instance should be running (which is desired).
First some (probably necessary) background information:
working on MAC OS X El Capitan (10.11.6)
I've got an Application made by node.js, electron and build by "npm build -m" (let's call it APP.app)
I installed the application App.app into program-folder by opening the built dmg-file and move it into the program-folder
Then I start the application App.app by click on the App.app-icon in program-folder
The application starts with a visible Window and also has an hidden background process running
If I close the visible Window, the App.app-Icon remains in the dock (which is okay, since the background-process is still running)
Now (and this is the difference to the windows build and running in windows), if I click again on the App.app-Icon in the program-folder, I only get a focus on the already running application INSTEAD of opening the window and close the old application (I can see te focus switch/activation by the switching menu name beside the apple-logo on top of the screen; it becomes "App")
the closing of the previous running instance is defined in electron code in the init-method as follows:
var shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) {
console.info('starting new instance');
initInternal(commandLine);
// Someone tried to run a second instance, we should focus our window.
var windows = options.closeWindowsOnRestart ? Browser.getAllWindows() : appWindows.slice();
windows.forEach(function (val, index) {
val.close();
});
readyCallback();
});
So, I did some homework and could figure out following:
my App.app-icon-click should look something like open /Applications/App.app
with this, I get the same problem as descriped above if I call it again (it only focusses the already opened window)
Now comes the funny part. If I open the application by calling directly /Applications/App.app/content/MacOS/App.app the old application-instance is closed and new App.app-application is started
I read through open-manual and could figure out, that if I use the -n-flag, the application starts succesful a new instance, too. (open /Applications/App.app -n)
I was wondering WHY? Do you have any clues? What is the difference between open and directly call of the application?
I suggest that the info.pklist in App.app-package is making the open-call different to the direct call of App.app.
BTW:
Unfortunately I already tried to add try-catch-blocks to debug the problem, but open does not give an output to terminal, it just opens the call whereas the direct call does not throw an error and everything works fine.
Anyway, I believe it's more a MAC OS X problem than an App.app-problem.
Hopefully there's somebody with same problems and a solution for me
Don't hesitate to ask for more details, if needed.
Short Version:
open starts the application with the LaunchService (and possible
added launch-parameters in info.plist)
whereas direct call of the
application just starts the application iself without any other
launch-options
*Long Version *
I read through the open manual (man open; Source: https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/open.1.html) and could figure out, that "the default application as determined via LaunchServices is used to open the specified files" if you click on an item.
So I read through the LaunchService-documentation and could figure out following:
"Opening Items by File-System Reference [...] default way:
If the designated item is an application: [...]
If the application is already running, it is activated (brought to the front of the screen) and sent an 'rapp' (“reopen
application”) Apple event."
(Source: https://developer.apple.com/library/content/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCTasks/LSCTasks.html#//apple_ref/doc/uid/TP30000999-CH203-TP9)
This reflects exactly my watching that if I click on the icon the second time, the app is just focussed/activated.
Thus I need the possibility to tell the application to open a new instance (oapp-event) instead of activating the already opened application (rapp-event)
Further reading lead me to following informations:
"Launch Options When opening an application (whether by itself or to
open one or more documents or URLs), you can specify various launch
options to control the manner in which it is launched or activated.
These can include: [...] Whether to launch a new instance of the
application, even if another instance is already running"
(Source: https://developer.apple.com/library/content/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCConcepts/LSCConcepts.html#//apple_ref/doc/uid/TP30000999-CH202-BABBJHID)
Thus I only need to add the "launch option" to define, that a new instance should be created instead of activating the existing one. But there's not written what the launch-option for it is and how they will be applied to the application (I suggest it belongs into info.plist-file).
So at least this is the answer to my original question, so I posted it here.
open - starts the application with the Launch-Service (and the defined option-parameters in info.plist)
whereas direct call of the application just starts the application iself without any other launch-options

watir 3 modal window access

I tried watir wiki example to access modal window. But was getting Argument error. I am trying with watir 3 version.
puts b.modal_dialog(:title, "showModalDialog Method Sample Target Page").exists?
puts b.modal_dialog(:title, "showModalDialog Method Sample Target Page").title
b.modal_dialog(:title, "showModalDialog Method Sample Target Page").close
b = Watir::Browser.new()
b.goto("http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/showModalDialog.htm")
b.button(:value,"Push To Create").click_no_wait
Error message
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/contai
ner.rb:60:in `modal_dialog': wrong number of arguments (2 for 0) (ArgumentError) from C:/webtest/popup.rb:29:in `<main>'
Can some one help how to access modal window using watir 3
Thanks
The error you're receiving is saying that you're supplying more arguments than are actually taken by the method.
I've never had call to use the actual modal methods within Watir, but after quick experimentation with the page you supplied I was able to interact with the modal using the following:
b.goto("http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/showModalDialog.htm")
b.button(:id => "dCommand").click_no_wait
puts b.modal_dialog.text
In the above example I had it print out the text of the modal, but presumably any regular Watir command could be substituted.
It would appear that the requirement for an argument indicating which modal to interact with has been removed in Watir 3.0 or earlier (presumbaly because you can only interact with one?). I moved to Watir-webdriver as I primarily test in Firefox, so I'm not sure when this might have changed, but it does appear to be the case that it does not accept any arguments in 3.0.

"object invoked has disconnected from its clients" error message is displayed while working with popup windows

I am trying to work with popup windows. I have gone through the site "http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups". I have modified the "ie-class.rb" by adding the code mentioned in the solution #7 of the site.
Also I have tried the example mentioned below :
require 'watir/ie'
require 'win32ole'
iewin = Watir::IE.new
iewin.goto("http://www.w3schools.com/js/tryit_view.asp?filename=tryjs_confirm")
iewin=Watir::IE.attach(:url, /w3schools/)
iewin.bring_to_front
iewin.maximize
iewin.button(:value, "Show a confirm box").click_no_wait
txt = iewin.clickprompt("OK") # waits for popup and click ok
puts txt #prints the popup text
txt1=iewin.clickprompt("OK")
puts txt1
iewin.close
On executing the following code, popups are handled but produces the following error :
C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:319:in `method_missing': unknown property or method: `name' (NoMethodError)
HRESULT error code:0x80010108
The object invoked has disconnected from its clients.
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:319:in `exists?'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:406:in `close'
from popup.rb:50:in `<main>'
Press a button!
You pressed OK!
But when I remove the command "iewin.close", error message is not displayed.
"iewin.close" command closes the browser and then there is nothing for watir to perform then why is the error message displayed.
Please suggest.
It appears that you are using ruby 1.9.2 with Watir. The watir installation page recommends using Ruby 1.8.7. That should fix the problem.
Good luck,
Dave
Notice that the output you have is not in order. You are seeing the error from closing the browser, BEFORE the output from your Puts.
Not sure if this is a treading issue or what, but in any event it looks from the output like the window is attempting to close before stuff that is dependent on it has finished. Perhaps try inserting a brief sleep for a second or five right before you try to close the window and see if you are still having issues.
Dug into this a bit. It appears that Ruby 1.9 is throwing a "NoMethodError" instead of a "WIN32OLERuntimeError". The Watir IE code reads as such
def exists?
begin
!!(#ie.name =~ /Internet Explorer/)
rescue WIN32OLERuntimeError
false
end
end
To fix this a second rescue can be added to the call
def exists?
begin
!!(#ie.name =~ /Internet Explorer/)
rescue WIN32OLERuntimeError
false
rescue NoMethodError
false
end
end
I don't know the side effects of adding such a call, but it does suppress the close warning.

Resources