I have a link on a page which only appears when hovering over a certain element. But I can't figure out how to emulate this and then click on the link so I can cucumber test it using Capybara and Selenium.
Anyone know how to do this? I've tried executing javascript and and also trying to talk to the selenium driver directly but so far I'm not having much luck...
This question is a few years old, so the answer might have changed. In newer versions of Capybara there are a few different ways to do it, depending on the driver you're using.
For selenium, you can execute javascript:
page.execute_script '$("#element").trigger("mouseover")'
Newer versions of selenium-webdriver support a hover method:
find('#element').hover
For capybara-webkit, the driver supports triggering events on the element:
find('#element').trigger(:mouseover)
I originally found the answer to this question from here and here.
Use Selenium's fireEvent on a mouseover event and then pause for your required hover time.
I have worked on similar one i used following see this might help you.
Using Selenium IDE.
1. Navigate to the required page.
2. Start selenium IDE and Get the Link target.
3. Change the Command to mouseOver Double click the the command in Selenium IDE.
4. It will Show the link wchich you needed.
5. Again Start recording and record the required Link.
When you Double click the mouseOver command it creates the simulation of mouse over through IDE and you can Use your mouse to record the popup link.
Thanks
I finally succeeded in getting Capybara + the Selenium driver to "hover" over an element. This is the code I'm using:
module Capybara
module Node
class Element
def hover
#session.driver.browser.action.move_to(self.native).perform
end
end
end
end
Related
i'm using selenium IDE for automation testing, i tried to use keypress on selenium, but because my site blocking any click and can only use keyboard for operating, i cant use sendkeys() to run it with selenium IDE because the empty target, is that possible to use sendkey without target? or is that another way to press key without target?
thanks for helping.
In regular Selenium you can sendKeys without a target web element with Actions.
As I see here this can also be done with Selenium IDE.
There are more additional documentations and tutorials about this.
Yes you could use ActionChains in regular Selenium, as mentioned in the previous answer. This definitely will work. But I am needed to use Selenium IDE.
A work around might be executing some JavaScript with the execute script command in Selenium IDE to trigger the key press that you need. That might work. I have found some code snippets online for that, but haven't yet worked it out. Actually I'm surprised that there's not a simpler solution.
I recently started using robotframework with the Selenium2Library. I haven't tested using Selenium before, but I know it is possible to record tests using Selenium. In RobotFramework, it says, "it is not possible". I mean even for a simple login test, I need to write the test, specifying the id of username, password and submit button.
However, is there any way by which these tests can be recorded using robotframework? such as clicking on a text box, entering a string and then clicking on submit button etc., and automatically generate the test case source code instead of having me to write the test cases. Is this possible with robotframework or any external library that it supports?
robotframework wasn't designed to be a record-and-play tool, and has nothing built-in to support that.
There was someone who wrote a selenium IDE plugin that would generate robot keywords, but that was years ago. The github repository is here: https://github.com/denschu/selenium-ide-format-robotframework
The code hasn't been touched since 2012, so I doubt it's of much use.
Using this Firefox add-on, FireRobot we can generate most of the code and also using this you can select the elements on the screen and get related code suggestions on right click like
Wait Until Element Is Visible
Click Element
and all operations to perform on the selected element.
I am using the Selenium IDE extension for testing webpages in FireFox and I was able to find out how to perform almost every command that I need to automate testing for my webpage.
Unfortunately I was not able to find out how to do this through the list of commands that you can manually enter into the queue of Selenium IDE.
I was wondering if anyone knew how to do this in the Firefox extension. Thanks!
You can use dragAndDropToObject command which locates the target element and drags it to the centre of the destination element.
dragAndDropToObject
target: locator of the element to drag
value: locator of the destination element
There is also a dragAndDrop command which drags the element by specified amount of pixels and drop it.
For one thing, you might want to use Selenium Builder instead of Selenium IDE. Also, there are some things that Builder or IDE cannot record, such as iFrame interactions, certain AJAX actions, and also drag and drops. For those, you need to code them by hand afterwards and get them working.
I am writing tests for a web application and all went well until I had to choose an option from a menu and that option displays a drop down list when hovered or clicked. When I click an option from the drop down list, I get the following error:
MoveTargetOutOfBoundsException: Element cannot be scrolled into view
Does anyone know what this error is about and what I should look for in my code?
Selenium version 2.25.0, java version 1.6.0_31
I've been checking some selenium and google groups regarding this issue in older versions https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/EuZ7a6_lB9Q
http://code.google.com/p/selenium/issues/detail?id=3075
http://code.google.com/p/selenium/issues/detail?id=4102
a more recent discussion
Is it a known issue for Selenium 2.25.0 or is there a way to fix it? I recently upgraded to Firefox 15.0 :|
Note: I found a temporary solution until someone magically fixes this...since I can't find where the problem is...
I run the code before that point where it crashes, I put it to sleep for 10 seconds, I manually click the menu and the option from the drop down list, the window I want is displayed and the code continues with actions from that point. It works for now...I hope this will be fixed since I can't believe that I can run a script in Selenium IDE but I can't run my java code in WebDriver ...this is crazy :|
I guess you are trying to click an element from a dropdown.
You should keep in mind, that Selenium helps you replicate exact human behavior. So if the code fails because the element is not visible, it is probably because the element is not visible.
To make it work, you might want to put a click command on the menu before the failing bit of code.
(to replicate the sleep 10 seconds manually click the menu button method you are using)
Once again, if you can show us your code and also the HTML snippet of the Menu section, we can provide an exact solution.
Maybe you're opening new popup window while opening select box.
This may help you:
WebDriver.FindElement(By.Id("someInputBox")).SendKeys("hello");
(IJavaScriptExecutor)WebDriver).ExecuteScript("document.getElementById('windowOpener_Button').click();");
WebDriver.SwitchTo().Window("newDisplayedWindowPopupName"); // continue to test
In Selenium IDE, the application has got image as button. The click event for that is not capturing. Is there any alternative Selenium Commands available for that or otherwise, is there any JavaScript user extensions can be added?
Please help.
Thanks
Yes.. the image will act as a button..
Found a solution for that!!
Simply added a JavaScript code which supports clickAt() commands.
To detect button as image you can use one of the below solution
xpath=//img[#src='/images/logo_home.png']
xpath=//img[#alt='Home']
//img[#src='/images/logo_home.png']