watir 3 modal window access - watir

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.

Related

pywinuto - click_input() function clicks on random node of tree view

I'm trying to automate the mmc (snap in console) type desktop app. Where I need to expand the tree.
Try 1 -
But when I do use expand() function it generates error popup which says that "the child nodes does not exists". After this script simply stops with no error message on console unless ok button is clicked on error popup. This I suspect because when tree node expanded it triggers some event which brings child nodes under it and somehow pywinauto is not getting Childs of this node. Please note that this error popup does not come up when the step is done manually.
Try 2 -
When I tried with select() then too same behavior observed as above. It generated same error popup.
Try 3 -
I tried click() and click_input() functions and it clicks on random tree node but not on the tree node on which it is called.
The all above trials are of my application which is not public.
For reproducing this issue I have tried it on common application available on windows OS. And we can see that the 3rd is still reproducible.
Reference code -
import time
from pywinauto.application import Application
from pywinauto import Desktop
app = Application().start(r'cmd.exe /c "C:\Windows\system32\perfmon.msc"', wait_for_idle=False)
app = Application(backend="win32").connect(title='Performance Monitor', timeout=10)
main_wind = app.window(best_match='MMCMainFrame', top_level_only=False)
console_wind = main_wind.child_window(best_match="MDIClients").child_window(best_match='MMCChildFrm').child_window(class_name="MMCViewWindow")
tree = console_wind.TreeView # print_control_identifiers()
children = tree.get_item(["Performance","Data Collector Sets"]).expand().get_child("System").expand().get_child('System Diagnostics')
print(children.text())
# below line will select the System Diagnostics
children.select()
time.sleep(4)
# Below line should click on System Diagnostics but it does NOT and same happens for click() function
children.click_input()
Any help will be really helpful in knowing why this click() and click_input() clicks on random tree node and Why expand() and select() method generates the non functional error popup?
Please mention if there is concrete workaround to this.
versions -
Windows OS 10, build 20H2
Python 3.10.4
comtypes 1.1.11
pip 22.0.4
pywin32 303
pywinauto 0.6.8
setuptools 61.2.0
six 1.16.0
wheel 0.37.1
TIA..
I have referenced some stack overflow and github issue tracker as for this problem as below but nothing works.
Treeview problem
select() for TreeView items (and similar) leads error if this selection calls other dialogs etc
Python: Click by coordinate inside a window
This was all because of incorrect backend API used for snap in control application. Unfortunately my POC I did on win32 API where it worked because I was doing some initial steps manually hence the problem I was facing(explained in try1) was not there and everything was working perfectly fine.
As soon as I switched the backend to UIA it gave me different identifiers for the controls that I used previously. Now I used this identifiers and started using UIA documentation and everything started working smoothly.
Also in my investigation there is no proper way to identify the backend API for the desktop application unless you try both and figure out which works for you.
Suggestion to readers - If you are using win32 API as backend there are different api methods available for that in the documentation. and for UIA backend different. read documentation carefully.
You can try the uispy tool and find that perfmon.msc can be automated with uia

NodeJS with Selenium-webdriver : Click on coordinates (x,y) properly

I am currently using chrome-webdriver with selenium-webdriver in NodeJS.
I instantiate the chrome browser with NodeJS, and use selenium-webdriver asynchronously to interact with it's elements
Currently, as my example: I am trying to click on the canvass on this site
however as noted on this question, selenium does not allow that.
there are other posted solutions but are for Java or C#. I have tried looking for the equivalent of the "Actions" library in JAVA or the "ActionChains" in python but failed.
I am trying to do this without Helium, as the challenge is to use open source.
currently I have a hold of the element below (I assume we get a hold of the div instad of the canvass... but I might be mistaken)
element = await driver.findElement(By.id("aww-container"));
however, I have tried the following with failed solutions
.clickAt(x, y) (returns error "clickAt() is not a function")
driver.elementFromPoint(x,y) (also returns error "clickAt() is not a function"
document.elementFromPoint (fails because I am executing javascript from nodejs.. not from the browser.)
Is there a way for my current setup to click on an element via the x and y coordinates asynchronously with my setup? I do not mind adding another library as long as it is open source.

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

Overriding PromptService in newer XULRunner

Our application uses embedded xulrunner. We override the default PromptService to provide custom dialogs for alert, prompt, etc by
componentRegistrar.RegisterFactory (PROMPTSERVICE_CID, aClassName, aContractID, MyPromptServiceFactory);
where,
PROMPTSERVICE_CID is "a2112d6a-0e28-421f-b46a-25c0b308cbd0"
CONTRACT_ID is "#mozilla.org/embedcomp/prompt-service;1"
When using XULRunner 1.9.* versions, this works perfectly and the call comes to MyPromptSerivceFactory. But, this doesn't work on newer XULRunner versions (>= 4.0)
I have modified the PROMPTSERVICE_CID to "7ad1b327-6dfa-46ec-9234-f2a620ea7e00" (copied from nsPrompter.manifest). While registering the factory I get the error NS_ERROR_FACTORY_EXISTS.
If I continue to use the old PROMPTSERVICE_CID, then nsIPromptService2 is not used instead nsIWindowCreator2.CreateChromeWindow2 is used to display alerts and prompts.
I have googled on this, but I couldn't find a solution to either fix the NS_ERROR_FACTORY_EXISTS error or for MyPromptServiceFactory to be used.
Any help/suggestions?
It would probably be better to use the existing prompt service the way Firefox does it rather than replace it. If you look at nsPrompter.openPrompt(), before opening a modal dialog it will try to locate and call a JavaScript function getTabModalPrompt() in the window containing the browser. It expects to get a promptBox element back and will call methods appendPrompt() and removePrompt() on it. Obviously, you don't have to give it a promptBox element, just something that behaves similarly - and displays a message any way you like.
But if you really want to replace system components, you shouldn't duplicate prompter's CID - use your own one but #mozilla.org/prompter;1 as contract ID (the old contract ID is for backwards compatibility only).

"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