We have problem that doubleClick in selenium isn't working.
We are using Actions for perform doubleClick like appear here: Selenium webdriver Java code using web driver for double click a record in a grid.
After investigation and several attempts we found that it is related to the speed of the doubleClick. As you may know, speed of doubleClick can be change. Is there any option to set the speed of doubleClick in selenium?
Code used to perform the double click:
Actions actions = new Actions(webDriver);
actions.doubleClick(element).build().perform();
And we try without 'build' too:
Actions actions = new Actions(webDriver);
actions.doubleClick(element).perform();
As seems you are using customized timing for double-click in your application, i suggest to try use 2 separated clicks with wait same between them of same customized timing. i think it's easiest way to control timing between two clicks.
Alternative workaround described here
Simplified answer (change to needed element):
((JavascriptExecutor) driver).executeScript("document.getElementById('map_container').dispatchEvent(new Event('dblclick'));");
Related
My scenario which produces the question goes something like below:
I enter a webpage via normal means, next I press on a button, to start a HTML5 application on this webpage, this application is inside an iFrame. On application start I'm being prompted to either turn the sound on or off. At this point there are two possible outcomes:
1. When I answer this prompt manually, new buttons appear in the application window, as expected.
2. When I answer this prompt through automation via Appium, new buttons do not appear.
Now to the question:
To answer the prompt I use the click() method from Selenium. Is it possible that this click() is not considered to be executed by a human and therefore doesn't trigger necessary things? And since I don't have access to the source of the application can I force the Selenium click() to look exactly like a human click?
Here is the code I use to execute the mentioned click:
//Application loading up, hence the sleep
Thread.sleep(5000);
AppiumTestBase.getDriver().switchTo().frame("e_iframe");
Thread.sleep(5000);
WebElement soundOff = AppiumTestBase.getDriver().findElement(By.id("soundOff"));
AppiumTestBase.getStandardWaitTime().until(elementToBeClickable(soundOff));
soundOff.click();
The program is able to find and switch in to the iFrame, there are no cross-origin issues either. The AppiumTestBase is just there for initializing the driver, setup capabilities etc. I also tried clicking the element via Actions and JavaScript, but there was no change in behavior.
In C# a workaround I've found to actually take control of the mouse and move it/click with it is to use "Microsoft.VisualStudio.TestTools.UITesting" for the Keyboard/Mouse libraries. From there, you can tell it "Mouse.Click(new Point(X, Y));"and it will move your mouse to that location and click.
Sample Code:
using Microsoft.VisualStudio.TestTools.UITesting;
var soundOff = AppiumTestBase.getDriver().findElement(By.id("soundOff"));
Mouse.Click(new Point(soundOff.Bounds.X, soundOff.Bounds.Y));
I have a application in which my pop-ups appear as Model Dialogs. My Application works only in IE.
No matter what different types of switches I use (switchToActiveContent, switchToWindow, switchtoFrame) I'm not able to switch my control to the new Model Dialog.
The solutions I've overcome is- Handling the Model Dialog through Robot Classes. But, I don't want to just handle and close the popup but perform actual operations and functions on it (my model pop-up has Web objects inside it)
Is there a definitive solution for this? Can Selenium WebDriver can't handle Model Popup dialogs at all?
Try using below code
string BaseWindow = driver.CurrentWindowHandle;
I'm testing a reasonably complex web application. I can get selenium to get things to the point where a button appears on the screen.
I want selenium to click that button after it appears. But it's not enough to use waitForElementPresent because when the button appears, it is disabled for a split second.
I need selenium to actually wait until the button is clickable before trying to click it.
I'm having no luck even trying to find out if this is possible within the IDE.
Thanks for any assistance!
It's worth re-iterating, right now I am using the IDE only. For now....
I had the same issue with Selenium IDE. I was looking for an equivalent to the ExpectedConditions.elementToBeClickable method in Selenium.
Using Selenium IDE, the following seems to work for testing an form submit input which is disabled using the disabled attribute. YMMV. Adapted as needed.
Add this Selenium IDE command before the click/clickAndWait/submit/submitAndWait command:
Command: waitForCssCount
Target: #submit-button[disabled="disabled"]
Value: 0
This css selector matches an element with id submit-button which has a disabled attribute set to 'disabled'. This command will wait until there 0 occurrences, i.e. the button is no longer disabled.
There is also a waitForXpathCount command available if you prefer to use a Xpath expression rather than a CSS selector.
Note: During testing i've noticed Selenium IDE being a little flaky and doesn't always reliably wait even with this waitForCssCount. YMMV.
I would really recommend you moving over to using webdriver 'proper', automating a complex app via just the IDE is going to cause you to end up in a mess eventually. However that is not your question and I have preached enough...
You have a few options, one might be that you get away with changing from waitForElementPresent to waitForVisible as element present just checks that the element exists on the page.
The next simplest change of that does not work is to hard code a wait into your script, hard coded waits are typically poor practice but you may get away with it if this is just a quick and dirty thing, just use the pause command (remember this takes time in milliseconds not seconds).
The last option is to use the more advanced feature waitForCondition which takes in a piece of javascript to evaluate, with this can you do extra checks on the element in question that can check for any property that identified it as ready to click.
I have seen that there is a waitForVisible command. You might want to try it.
Waiting for the DOM to load the element (waitForElementPresent) and the loaded element actually becoming visible (waitForVisible) could be two different things.
You could just use waitForElementNotPresent and give the button CSS with the disabled attribute. If the disabled attribute does not exist, the button is active, so there you have your code.
Here is the example that I used for Selenium IDE:
Command | Target | Value
waitForElementNotPresent | css= input[disabled=""]|
Your CSS can differ from your code, like having disabled="disabled" as a state, but the principle remains the same.
Using a CSS selector, I was able to use the not pseudo-selector in combination with wait for element visible.
wait for element visible
css=.btn.btn-primary:not([disabled=disabled])
I am relatively new to Selenium and it's capabilities So far I have found it's just the tool to use for automated regression testing for a web application. And it's for this regression testing suite that I am in the process of building that I have come to a problem. In the web app I have a page that displays a Jquery Datatable with some rows in it. Each row is bound with a context menu. That pop's up as a DIV floating on the top most Z-order, with absolute positioning all controlled with Jquery.
What I am attempting to do in selenium is to physically use this menu so that I am able to warp it with the appropriate regression tests. I have has some success with using the Actions class to call the context menu up. What I am not able to do is to have the mouse move to the menu Items can click them. I have been trying to use the MoveByOffset method but I don't seem to be having any luck in getting it to click on anything in the menu. I also have had no luck in working out where on the page the mouse is currently located thus not able to prove is anything is actually happening.
any help or advise on this will be gratefully received.
Thanking you all in-advance.
This is the code that I am currently using to attempt to drive this context menu. the values in the MoveByOffset have literally been every combination of 10 & -10. to try and hit the first menu item.
public void ClickAction_myPOTSIcontextmenu(IWebElement Row)
{
Actions builder = new Actions(this._driver);
IAction action = builder.MoveToElement(Row).ContextClick().MoveByOffset(-10,-10).Click().Build();
action.Perform();
}
Hope this helps,
WebElement element = driver.findElement(By.cssSelector("selector_for_element"));
Locatable hoverItem = (Locatable) element;
Mouse mouse = ((HasInputDevices) driver).getMouse();
mouse.click(hoverItem.getCoordinates());
I am using the selenium plug in for eclipse to automate the testing of newly created websites. I am trying to click a button that is in a menu and only visible when the cursor is located over the menu.
Is it possible to move the cursor so that this button can be clicked ?
It will depend a little on how the menu has been implemented (i.e. the event that will trigger your button to appear) but you should look at the focus and mouseOver methods for selenium.
I.e. do something like
this.selenium.mouseOver(element);
where element refers to the menu and then do a click on the button. If mouseOver does not work (i.e. the button does not become available) try focus instead.
It's unclear if you're using Selenium RC or Selenium 2 and WebDriver.
I can only speak to the latter, but you can use Actions to move the mouse and click. The basic idea is you define an object that is a series of actions, and then you perform those actions.
An introduction on how to use these is at http://code.google.com/p/selenium/wiki/AdvancedUserInteractions, and a good writeup with Python examples is http://www.theautomatedtester.co.uk/blog/2011/selenium-advanced-user-interactions.html
It sounds like in your case, you would have something like:
Actions menuClick = new Actions(driver);
builder.MoveToElement(menuElement)
.MoveToElement(buttonElement)
.click(buttonElement)
Action menuClick = builder.build();
menuClick.perform();