Selenium Java trying to click with remote webDriver - java

I have to test with selenium a Web Application.
This :
action.moveToElement(webElement,x,y).build().perform();
Is working for 99% of my web elements...
Now I have a web element that is not detected by Selenium IDE.
My boss explains to me that this web element is a kind of plugin. This web element display video from camera.
When I try with Selenium IDE my click isn't detected.
That's why I tryed to do it with action.moveToElement(webElement,x,y).build().perform();
I have a webPath (CSS XPath) for this web element. When I try
webdriver.findElement(By ...).click();
It's not working but I don't have an exception. I guess Selenium do a click and I don't understand why it's not working.
dailymotion.com is like youtube.com (I can't use youtube at work...)
When I try to click on pause on a daylimotion video Selenium IDE don't detect my click. I guess this is the same problem.
I have found this constructor : public Actions(Keyboard keyboard, Mouse mouse) but I don't know how to use it.
I think I can't use java.awt.Robot because I'm working with Selenium grid and I have a lot of node...
Any suggestion ?

If can't able to find the webelement you can use coordinates to simulate click..
Actions builder = new Actions(driver);
Action action= builder.moveByOffset(40, 40).build();//change the x and y coordinate accordingly
action.perform();

Related

Selenium click chrome physical buttons like menu, left, right navigation, bookmarks

I'm working on a some automation work, as per my requirement I need to click on Chrome Physical buttons like left nav, right nav, bookmarks, menu etc. I can do with shortcuts but my requirement is to click on browser buttons. Any ideas would be helpful. Thanks in advance.
As per your question you want to click on Chrome Physical buttons like left navigation, right navigation, bookmarks, menu etc.
But if you look into the documentation in Selenium Home Page it clearly mentions that :
The entire suite of tools provided by Selenium results in a rich set of testing functions specifically geared to the needs of testing of web applications. These operations allow many options for locating UI elements and comparing expected test results against actual application behavior.
So factually Selenium by design interacts with the HTML DOM and the WebElements located in the DOM Tree
Now the desired controls e.g. left navigation, right navigation, bookmarks, menu are out of the DOM. Hence you cannot mock the click on those controls.
However all the Selenium Language Binding Art provides a handfull of methods to achieve the same result. Here are a few from the Selenium Python Binding Art :
Maximize : To maximize the browser window.
driver.maximize_window()
Minimize : To minimize the browser window.
driver.minimize_window()
Close : To close the browser window.
driver.close()
Quit : To close the browser window gracefully.
driver.quit()
Refresh : To refresh the url.
driver.refresh()
Forward : To move forward.
driver.forward()
Back : To move backwards.
driver.back()
And of-coarse Get : To invoke an url.
driver.get('http://google.com/')
There are functions for this that is built-in:
driver.forward()
driver.back()
https://selenium-python.readthedocs.io/navigating.html#navigation-history-and-location
It doesn't appear that selenium can interact with the Bookmark, but let me check some more.
This can't be done with selenium webdriver and I think also not with the standalone selenium server. Selenium only allows to interact with the DOM.
The only way to achieve what you want to do is to use an automation tool that actually runs directly in the OS that you use. Java can be used to write such a program.
I would however recommend to not go this route. Instead try to convince whoever is responsible for your requirements to re-think and allow to use other means of achieving back and forward actions.

Select the "back" button of the Firefox browser to right click and Select the Option from the right click Menu in Selenium Web Driver - Java

I am using Selenium webdriver . I want to select the "back " button of the firefox and right click the back button and select an option.
I see there is "Actions" API to right click, But i am not able to select/find the "back" button element of the firefox to right click using selenium .
Can any one please help me .
Code iam trying is :: Using firefox Driver to inittate the Webdriver
Actions action= new Actions(driver);
action.contextClick(productLink).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();
In the above code , in place of "productlink", i should select the back button element of the firefox browser to right click .
You cannot do that with Selenium.
You can use AutoIT with Selenium to click on that.
Refer to the following article on how to use AutoIT.
http://toolsqa.wpengine.com/selenium-webdriver/autoit-selenium-webdriver/
Here is what you can do. Try to use "Navigation" Commands in selenium.
driver.navigate().to("http://www.DemoQA.com");
there are many commands you can perform on it. If you still find issues using it let me know.

CRM 2015 Automation Testing using selenium, Change Focus after Click

I'm using Selenium scripts using Java to automate a project in CRM 2015. When I tried to click on a button using IE Webdriver it navigates correctly but focus still on clicked button and then cannot find any controls as It's implement using Single App page. Could you please give me workaround ? I tried :
driver.switchTo().defaultcontent();
driver.switchTo().ActiveElement();
but not working and still on clicked button focus.

Can I have a mouse event specific to a browser window?

I am using Selenium Webdriver for Automation, and there are few flex objects which I need to interact with. I know that Webdriver could not interact with flex objects.For that I have integrate the Webdriver with the ROBOT framework.
The problem I am facing is that I need to have focus on the current window for the mouse to detect the location of an element. If I touch My mouse while the execution is in progress, the element could not be found.
Can anyone please suggest me some alternatives to trigger a mouse event explicitly for the browser window, So that I can work on other things while my test execution is in progress?
I am using Java.
I don't believe that this is possible with Robot. However, if you use the Actions API, then you can mouse over stuff, and so forth without having the computer actually use your mouse.
Actions actions = new Actions(driver);
actions.moveToElement(someElement);
actions.click();
actions.perform();

Selecting an option in a CSS-based menu with WebDriver

I have a simple CSS-based dropdown menu, and I'm trying to click on one of the menu items in a Java Selenium (WebDriver) test.
Both the menu (<ul> element) and the items (<a>) have IDs and creating corresponding WebElement objects works fine. I'm trying to click on one of the items with code like:
hoverOver(transfersMenu);
transferLink.click();
In hoverOver(), I've tried all three answers from this question, but none of them work. I keep getting:
org.openqa.selenium.ElementNotVisibleException:
Element is not currently visible and so may not be interacted with
Command duration or timeout: 2.06 seconds
(I've tried calling transferLink.click() also before hoverOver(), in the hope that the implicit wait would make it work, but nope.)
Any idea how to make the hovering work so that the link can be clicked?
Selenium version 2.21.0. I'm running the tests on Linux (Ubuntu), using Firefox 13.0. A colleague just tried on Windows (using Firefox 12.0), and it didn't work for him either.
Update: As per Slanec's tip in comments, and these instructions, I tried setEnableNativeEvents(true) on the FirefoxProfile. At first this failed:
org.openqa.selenium.InvalidElementStateException:
Cannot perform native interaction: Could not load native events component.
...but after I upgraded to Selenium 2.23.1, I no longer get that complaint.
Still, the hovering doesn't work (with native events on or off). :-/
I use the following code to hover over our menus for 1 second, before clicking a link, just like the one you are using:
action = new SeleniumActionHelper(driver);
WebElement currentUser = findElementByLinkText("testing1");
action.mouseHover(currentUser);
Thread.sleep(1000);
Of note, the mouse cursor needs to remain in the browser window for the hover to keep. If the mouse cursor is outside of the browser window, I experience a quick flash of the menu, but it does not stay visible
Try this exampale:
WebElement menuHoverLink= driver.findElement(By.id("test"));
actions.moveToElement(menuHoverLink).perform();
driver.findElement(By.id("test")).click();
Thread.sleep(6000);
How do you run your test classes? I found out that running WebDriver through ANT makes hover actions impossible, whereas running the test classes from command line (TestNG JAR) or from Eclipse works just fine.

Categories

Resources