I am using Ruby/Cucumber
my page:
class DemoContextMenuPage
include PageObject
include DataMagic
page_url 'http://the-internet.herokuapp.com/context_menu'
h5(:context_menu_title, :css => '.example > h3:nth-child(1)')
div(:context_menu_hotspot, :id => 'hot-spot')
end
my step:
When /^I right click context menu hot spot$/ do
on(DemoContextMenuPage).context_menu_hotspot_element.right_click
end
my feature:
Scenario: Verify right click menu
Given I am on the context menu page
When I right click context menu hot spot
result:
undefined method `context_click' for # (NoMethodError)
no issues with watir-webdriver only selenium-webdriver Se=2.53.4, watir=0.9.3
This is a bug in the Page Object gem. You can see from the page object's Selenium implementation that it does:
def right_click
element.context_click
end
context_click is not a method defined for Selenium elements.
As seen from the Watir source code, context clicks need to be done using the action builder:
driver.action.context_click(#element).perform
Unfortunately, there does not appear to be a way to get the Selenium::WebDriver from a Selenium::Element. I think you will need to call the context click from the page object:
on(DemoContextMenuPage) do |page|
e = page.context_menu_hotspot_element.element
page.browser.action.context_click(e).perform
end
Related
I am fairly new to PyQt5. So here, I am trying to work on a project in which first window in login page dialog window. So if password entered are correct it will open another window.
def login(self):
eid=self.lineEdit.text()
epass=self.lineEdit_2.text()
if eid==idd and epass==passs:
from BloodBank import Ui_MainWindow
self.MainWindow = QtWidgets.QMainWindow()
self.ui = Ui_MainWindow()
self.ui.setupUi(self.MainWindow)
LoginPage.hide()
self.MainWindow.show()
else:
self.msgdlg("Wrong ID or Password!")
In this Window, from title bar menu action, I tried to attach yet another window, which when opened, current window become hidden. For this I wrote following code:
def menu(self,action):
txt=(action.text())
if txt=="Blood":
try:
from Blood import Ui_MainWindow
self.MainWindow1 = QtWidgets.QMainWindow()
self.ui = Ui_MainWindow()
self.ui.setupUi(self.MainWindow1)
MainWindow.hide()
self.ui.updatelist()
self.MainWindow1.show()
except Exception as e:
print(e)
Now, When I run above code without MainWindow.hide() it run perfectly fine. But as soon as I feed MainWindow.hide() it gives following error.
name 'MainWindow' is not defined
When I try same .hide() funtion with login page, it works.
What do I need to do so I can hide my window?
Your code is a bit unclear, but i think it should be self.MainWindow.hide() because we are trying to hide our parent widget.
Edit
Try self.hide() in the bloodbank file instead of MainWindow.hide() I am assuming that in the file bloodbank you have your mainwindow.
Here is the problem, you have two files the Login File which consists of the loginpage and the bloodbank file.
when you created a the instance of self.MainWindow it is only in the namespace of the loginpage.
And you try to open a another window from this file (which is the 2nd part of your code). MainWindow instance is not present because you have defined (instantiated) in another file (login page).
I would like to take different actions when an swt menu is shown or hidden, so I am adding a MenuListener to a Menu
If I create the listener using a class and add an instance of that class via add_menu_listener I can separately detect showing events and hiding events. For example using the following Listener class:
class MyListener
include MenuListener
def menu_shown e
puts "#{e} was a show event"
end
def menu_hidden e
puts "#{e} was a Hide event"
end
end
and then add the listener to the menu via
my_menu.add_menu_listener MyListener.new
will print different messages when the menu is shown vs hidden.
I can also add a listener using "closure conversion" for example this will produce a message whenever the menu is shown or hidden.
my_menu.add_menu_listener { |e| puts "#{e} was a menu event" }
These two sections of the jruby wiki seem to cover implementing interfaces in jruby.
https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#implementing-java-interfaces-in-jruby
https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#closure-conversion
The second section seems to indicate that this "closure conversion" method should work for any interface, but I can't figure out out to get it to separate out the two different methods.
Does anyone know how to use this "closure conversion" scheme to implement each of the specific interface methods separately?
Looking more closely at https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#closure-conversion
I see this statement:
The block is converted to a Proc object, which is then decorated with
a java interface proxy that invokes the block for any method
called on the interface.
I think this means there is no way to tell what method called the block.
What I decided to (unless someone has a better solution) is this
show = "Show"
hide = "Hide"
my_listener = MenuListener.new
my_listener.define_singleton_method(:menu_shown) { |e| puts "#{e} was a #{show} event" }
my_listener.define_singleton_method(:menu_hidden) { |e| puts "#{e} was a #{hide} event" }
my_menu.add_menu_listener my_listener
Note:
I chose this over
my_listener = MenuListener.new
class << my_listener
def menu_shown e
...
end
def menu_hidden e
...
end
end
my_menu.add_menu_listener my_listener
since I need to reference some free variables as shown above
I'm trying to click on a tag with watir classic 3.7.0 which is unsupported. Generally, it looks as though I can find the tag with a line such as:
browser.td(:id, 'Proceed').element(:tag_name => 'FONT')
and
browser.td(:id, 'Proceed').element(:tag_name => 'FONT').class
returns watir::HTMLElement, but I cannot find any documentation for this (only Element)
using
browser.td(:id, 'Proceed').element(:tag_name => 'FONT').methods
shows that it has the method click, but running
browser.td(:id, 'Proceed').element(:tag_name => 'FONT').click
results in :
undefined method 'each' for "FONT":String (NoMethodError)
I have tried making a module for the font tag:
module Watir
module Container
def font(*args)
FONT.new(self, extract_selector(args).merge(:tag_merge => "font"))
end
def fonts(*args)
GCollection.new(self, extract_selector(args).merge(:tag_merge => "font"))
end
end
class FONT < Element
end
class GCollection < ElementCollection
def element_class
FONT
end
end
end
but this throws the error,
undefined_method 'extract_selector' for #<Watir::TableRow:0x2835378> (NoMethodError)
How do I click on this unsupported tag?
It looks like you are running into Issue 62.
Solution 1 - Upgrade Watir-Classic
This bug is fixed in the latest version of watir-classic. Note that you need to upgrade the watir-classic gem (not just the watir gem):
gem install watir-classic
Solution 2 - Use an Array
If upgrading to the latest version is not an option, you can make the :tag_name value an array:
browser.td(:id, 'Proceed').element(:tag_name => ['FONT']).click
Solution 3 - Use font method
I just double-checked and the font element is actually supported. So I would say the better solution, for this specific case at least, would be to use the font method:
browser.td(:id, 'Proceed').font.click
I'm building a simple todo list using Rails (3.2.5).
I show all of the users todo items in an unordered list, each list item being the todo itself. By clicking on the todo item the user marks it as completed. Using jQuery I give the li a class of done so I can change its styling. By clicking on a "Clear completed" button I want the completed items to be destroyed (and deleted from the database).
How can this be done?
NB: I'm basically trying to recreate this app using Rails: http://davidpdrsn.com/todos/
You can do it using a remote form
So you would have something like
you would have a form with remote: true for each item or you could have only one form and submit it with JQuery.
class TodoController
def set_completed
#todo = Todo.find(params[:id])
#todo.done = true # you could move this to your model and do something like #todo.done! and that would save it automatically
#todo.save
end
def destroy_completed
#todos_to_delete = Todo.where(done: true)# here you could also move it to your model and do it like Todo.completed
#todos_to_delete.destroy_all
end
end
and you would render the response with the js for formatting, or even removing items on your list, like
views/todo/set_completed.erb.js
$("#item_<%= #todo.id %>").addClass("completed");
Supposing the model is called Todo and the completed column is called completed, you can write one of these in the controller:
Todo.destroy_all(:completed => true)
Todo.where(:completed => true).destroy_all
If you need help with how to manage the ajax request/response, here there is a good start (sorry, I don't want to give you the solution, IMHO you should make your way by yourself)
Resources: ActiveRecord#Base::destroy_all
i will be short.
As far as i know watir library provides two methods for getting html elements.
Almost for each element (div, button, table, li, etc) watir provides two methods:
. One is the 'singular' method which gets only one specific element. For example:
watir_instance.div(:id,'my_div_id')
watir_instance.link(:href,'my_link_href')
watir_instance.button(:class =>'my_button_class', :index => 4)
These methods will only retrieve A SINGLE ELEMENT. Thats ok...
. The second is the 'plural' method that will retrieve ALL the elements of the watir instance
watir_instance.divs
watir_instance.links
watir_instance.buttons
But as far as i know watir doesn't provide a method to get more than one element giving certain conditions.
For example... If i want to flash all the links with id:my_link_id it would be very easy to do something like this:
watir_instance.divs(:id, 'my_link_id').each do |link|
link.flash
end
With hpricot this task is very easy... but if your aim is not to parse i couldn't find a Watir Method that does what i want.
Hope you can understand me...
Cheers, Juan!!
Juan,
your script has several problems:
You say you want to flash all links, but then you use watir_instance.divs. It should be watir_instance.links
you pass arguments to divs method: watir_instance.divs(:id, 'my_link_id'). It should be just watir_instance.divs
Your example is also strange:
i want to flash all the links with
id:my_link_id
As far as I know, id should be unique at the page.
So, here are different examples:
1) Flash all links on this page:
require "watir"
b = Watir::IE.start "http://stackoverflow.com/questions/1434697"
b.links.each do |link|
link.flash
end
2) Flash all links on this page that have questions in URL (bonus: scroll the page so the link that is flashed is visible):
require "watir"
b = Watir::IE.start "http://stackoverflow.com/questions/1434697"
b.links.each do |link|
if link.href =~ /questions/
link.document.scrollintoview
link.flash
end
end