I have canvas element on my page and i want to click on some part of it.
I know, that I must use ActionBuilder to do this, so I tryed this code:
element = driver.find_element(:xpath, canvas_xpath)
action.move_to(element, 100, 100).click.perform
But this code only click in center of canvas element and don't move mouse in any way.
Is there any other possible way to move mouse to some coordinates?
(Don't mention AutoIT scripts - I develop under Linux)
I have the same problem in IE. ShockwaveNN's code works for me in Firefox and Chrome. I think the problem is that "click" clicks in the middle of the element. Below is the documentation in action_builder.rb:
#
# Clicks in the middle of the given element. Equivalent to:
#
# driver.action.move_to(element).click
#
# When no element is passed, the current mouse position will be clicked.
#
# #example Clicking on an element
#
# el = driver.find_element(:id, "some_id")
# driver.action.click(el).perform
#
# #example Clicking at the current mouse position
#
# driver.action.click.perform
#
# #param [Selenium::WebDriver::Element] element An optional element to click.
# #return [ActionBuilder] A self reference.
#
According to this and my conclusions, it should just be to execute these actions in two lines like:
element = driver.find_element(:xpath, canvas_xpath)
driver.action.move_to(element, 100, 100).perform
driver.action.click.perform
or
element = driver.find_element(:xpath, canvas_xpath)
driver.action.move_to(element).perform
driver.action.move_by(100, 100).click.perform
Sadly, none of this works (for me in IE) : (
Did you try action.move_to(element).move_by(100, 100).click.perform ?
The click occurs at the center of the target element (see comments 3 and 5 http://code.google.com/p/selenium/issues/detail?id=3578)
Commands: http://selenium.googlecode.com/svn/trunk/rb/lib/selenium/webdriver/remote/commands.rb
ActionBuilder: http://selenium.googlecode.com/svn/trunk/rb/lib/selenium/webdriver/common/action_builder.rb
Related
I am trying to create a node graph in pyside2.
It has multiple files, one which handles all the events.
I am implementing the tab keypress event so and just want to print something when tab is pressed. This works fine but when i add the code my whole node graph is cropped and cut off. Seems weird.
Here's the code i add that screws it up:
def event(self, event):
if event.type() == QtCore.QEvent.KeyPress:
if event.key() == QtCore.Qt.Key_Tab: # tab
event.accept()
print("Tab pressed")
return True
Before i add the event code:
After I add the event code:
The ruby code below prints two windows (overlapping) via Curses. The first "border" window prints in black/cyan and the "content" window prints in blue on cyan.
The content window only displays the background color where text is printed. The rest of the content window remains black. The ruby dox describe ways to manipulate window backgrounds using either color_set, bkgd or bkgdset methods. I can only get color_set() to work however and only for text that is being printed:
How can I fill the reset of the content window with the appropriate background color? I found some code to Set a window's background color in Ruby curses but it does not seem to work and is quite old. The only other idea I have is to right-pad the string with spaces to fill the entire window with the background character but this seems reeealy hacky.
EDIT: added code
EDIT2: added "hacky padding" work around
#!/usr/bin/ruby
require 'curses'
Curses.init_screen
Curses.start_color
Curses.noecho
Curses.cbreak
Curses.refresh # Refresh the screen
xulc = 10
yulc = 10
width = 30
height = 8
# text color for border window
Curses.init_pair(1, Curses::COLOR_BLACK, Curses::COLOR_CYAN)
Curses.attrset(Curses.color_pair(1) | Curses::A_BOLD)
# Text color for content window
Curses.init_pair(2, Curses::COLOR_BLUE, Curses::COLOR_CYAN)
Curses.attrset(Curses.color_pair(2) | Curses::A_NORMAL)
# border window
win1 = Curses::Window.new(height, width, yulc, xulc)
win1.color_set(1)
win1.box("|", "-")
# content window
win2 = Curses::Window.new(height - 2, width - 2, yulc + 1, xulc + 1)
win2.color_set(2)
win2.setpos(0, 0)
# only prints in background color where there is text!
# add hacky padding to fill background then go back and print message
bg_padding = " " * ((width - 2) * (height - 2));
win2.addstr(bg_padding);
win2.setpos(0, 0)
win2.addstr("blah")
# prints without the color_set() attributes
#win2.bkgd ('.'.ord)
# make content visisble
win1.refresh
win2.refresh
# hit a key to exit curses
Curses.getch
Curses.close_screen
Ok, so I found this, the actual code is here:
It's been a while, but maybe my examples are still useful:
It is the same "diamonds" for me when using
window.bkgd(COLOR_RED) This seems to appear, because the bkgd method
takes a char and prints it to all free spaces of the window (see old
doc).
However, then you can use a color pair with the wanted background
color and apply it to all screen positions before writing oher stuff.
Here is how I solved it:
require 'curses'
init_screen
start_color
init_pair(COLOR_RED, COLOR_WHITE, COLOR_RED)
window = Curses::Window.new(0, 0, 0, 0)
window.attron(color_pair(COLOR_RED)) do
lines.times do |line|
window.setpos(line, 0)
window << ' ' * cols
end
end
Also found this:
# color_set(col)
# Sets the current color of the given window to the foreground/background
# combination described by the Fixnum col.
main_window.color_set(1)
tutorial.html#colors-initialization
Guess I'll use the hacky padding workaround. Seems to be all I've found so far
this part of code shows the buttons as they are know to be used in tkinter
up = Radiobutton(frame1, text="up", variable=rows, value=1,indicatoron=0)#button for movingup
up.grid( row=2,column=0 )
down = Radiobutton(frame1, text="down", variable=rows, value=2,indicatoron=0)#button for moving down
down.grid( row=3,column=0 )
left = Radiobutton(frame1, text="left", variable=cols, value=3,indicatoron=0)#button for moving left
left.grid( row=2,column=4 )
right = Radiobutton(frame1, text="right", variable=cols, value=4,indicatoron=0)#button for moving #right
right.grid( row=3,column=4 )
vertical=Entry(frame1,bd=2,width=10)
vertical.grid(row=4,column=0)
horizontal=Entry(frame1,bd=2,width=10)
horizontal.grid(row=4,column=4)
enter=Button(main,text='Enter',command=move) #displays the move on grid once button is pressed
enter.pack()
label = Label(main)
label.pack()
You can bind function to key - ie.
root.bind('m', move) # key `m`
root.bind('<Control-m>', move) # key `Ctrl+m`
root.bind('<Alt-m>', move) # key `Alt+m`
root.bind('M', move) # key `Shift+m`
but it will be executed with extra argument
move(event)
so you have to define function with extra argument too
def move(event=None)
and you can set default value for event (ie. None) so it will work also with command=move
I created a class that I am trying to make to simulate richtextbox, sort of, on windows forms. this means when you add new data to the form/richtextbox it is added to the bottom of the box/window and the rest is scrolled up one line.
ive tried to enable scrollok(), but it does not seem to want to scroll. i am not sure if it's bugged or my way of implementing it is wrong.
class Textpad
attr_accessor :data, :name, :window
def initialize(name, height, width, startx, starty)
#data = []
#name = name
#height = height
#width = width
#startx = startx
#starty = starty
Ncurses.refresh
#window = Ncurses.newwin(height, width, starty, startx)
#window.scrollok true
#window.wrefresh
end
def add(packetid, username, message)
#data.push [Time.new.strftime('[%T]'), packetid, username, message]
#data.shift if #data.length > 500
end
def draw
Ncurses.init_pair(1, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK)
Ncurses.init_pair(2, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK)
Ncurses.init_pair(3, Ncurses::COLOR_RED, Ncurses::COLOR_BLACK)
Ncurses.init_pair(4, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK)
#window.wclear
position = 0
#data.each do |timestamp, packetid, username, message|
case packetid
when '1005'
#window.mvwprintw(1*position, 1, "#{timestamp} «#{username}» #{message}")
#window.mvchgat(1*position, timestamp.length+2, 1, Ncurses::A_NORMAL, 3, NIL)
#window.mvchgat(1*position, timestamp.length+3+username.length, 1, Ncurses::A_NORMAL, 3, NIL) #colorize the symboles around the username
end
position += 1
end
#window.wrefresh
end
end
the problem would be inside my draw method of the Textpad class. i can fill the data array for the Textpad class with hundreds of entries but only the very top of the array gets written (until it reaches the bottom of the window) with no scrolling. Do i manually have to scroll the screen or something? from the documentation it says it should automatically scroll when the cursor reaches the bottom and another line is added.
To quote the man page:
The scrollok option controls what happens when the cursor of a window is moved off the edge of the window or scrolling region, either as a result of a newline action on the bottom line, or typing the last character of the last line. If disabled, (bf is FALSE), the cursor is left on the bottom line. If enabled, (bf is TRUE), the window is scrolled up one line...
What is happening in your code is that you are attempting to print outside the window which is an error, but an error that curses handles by not printing anything.
You can either print an new line when you get to the bottom of the window or once your reach the bottom of the window you can call #window.scroll.
Either way you will need to keep printing on the last line if you are explicitly setting the position.
Shoes is very handy GUI tool. I would like to do a search form so that a user is helped to navigate through larger texts for editing. For this I need to move the cursor within an editbox element.
Here you'll see my question in code:
Shoes.app do
stack do
p=para "After pressing 'search' a question will arise"
box=edit_box
box.text="One\nof\nthe\nmost\nstriking\ndifferences\nbetween\na\ncat\nand\na\nlie\nis\nthat\na\ncat\nhas\nonly\nnine lives."
flow :margin_top=>0.1 do
search=edit_line
button("search") do
pos=box.text.index search.text
y = box.text[0..pos].split.size-1 if pos
if not y.nil?
#For example if you searched "only" then
#cursor should jump/scroll to line 17.
#
#Anything there for cursor positioning,
#like: box.cursor=[0,y]
#
p.text="How can I move editbox's cursor in line #{y+1}?"
else
alert "'#{search.text}' not found"
end
end
end
end
end
Is there is any way to change cursor's position of an editbox? If not, do you know an alternative way of implementation?
Unfortunately, Shoes doesn't seem to provide any way to do that. These are the only methods defined on EditBox (it inherits from Native, which has several methods, but again, none to reposition the cursor).
rb_define_method(cEditBox, "text", CASTHOOK(shoes_edit_box_get_text), 0);
rb_define_method(cEditBox, "text=", CASTHOOK(shoes_edit_box_set_text), 1);
rb_define_method(cEditBox, "draw", CASTHOOK(shoes_edit_box_draw), 2);
rb_define_method(cEditBox, "change", CASTHOOK(shoes_control_change), -1);
http://github.com/why/shoes/blob/cea39a8bf9a5b7057b1824a9fab868d1f8609d69/shoes/ruby.c