In browser(Firefox or Chrome) user performs many actions such as filling input or pressing submit button etc. Is there anyway(in Java) where we can record these actions(which component he clicks or Xpath of that element) on client side? Selenium has Webdriver but i am unable to find if it can does this.
There are a Java library called JSFlight.
This tool is splitted into three main parts:
Recorder - it's the set of the javascript files, that you should insert into your html document. You can configure which types of events you want to track. It can work with iframes too.
Player - this is the main program/library which plays recorded events.
Server - it's the wrapper upon the Player. Starts a standalone server with rest api. Uses the MongoDB.
Related
I am currently working on learning selenium and my current requirement is to read an API JSON response when a certain button inside my application UI is clicked.
I mainly use Java and selenium but I have the flexibility in using any other language.
The click triggers an event which hits an API and a response is received. Hitting the API directly without going through the UI is not an option.
Additionally, when using Developer Tools in chrome, i can see the response in the "Network" tab. If there is any way that i could just read the "Network" tab, that is also acceptable.
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.
If I have a random program, that shows some text and has some text input, is there a way to write a java program, that reads that text labels and/or fill that text input fields and press an ok button?
Text applications are things that run on the cli, and have no windows. On Microsoft Windows the 'dir' command is an example.
Graphical applications are things that the beginning user might see, and has buttons, text boxes, scroll bars and stuff like that. On Microsoft Windows the 'paint' program is an example.
Web applications are websites that provide front ends as web pages. The 'gmail' application is an example.
If you want to interact with an application using Java, the application type will determine your approach.
text application - use ProcessBuilder, it's a java class designed to launch and (to a degree) interact with processes through stdin, stderr, and stdout.
Graphical application - It depends on the graphical widgets the application uses. If those are not supported by a library that can navigate the presentation, then input is limited to x,y coordinates from the application's origin, and input could fail to go into the right component.
Web applications - Use selenium. It is a custom web browser solution that permits testing of web sites; but, you could use it for your task. It is big and complicated, but considering what is required for this task, it is comparatively easy to use.
Yes you can write a new program that can give input and trigger the service of 'OK' key.
Your first program needs to be designed in the way that - it should accept the input from second program.
You can design the first code as web service in a web application . your first program will be web service provider and second program will be web service consumer.
Using second program you can post the required data to first code. and all the triggers of 'OK' button can be processed from first application.
I am writing tests for a Java application which has been developed using the Vaadin framework. For the tests I am using Robot Framework. At some steps I have to use robot framework commands like execute javascript.
For example, for finding a component I have to execute the following command:
execute javascript document.getElementById('button-create').click()
Which works without any problem. Primitives like Click Element are not working because Vaadin doesn't wait until the whole page is loaded and therefore some ids are not yet assigned at run time.
Unfortunately this application has been developed in such a way that some components are not reacting to the event click but to the event mousedown. That is, at the Java console of chrome I can perform the following command:
document.getElementsByClassName('table-cell-wrapper')[1].mousedown();
and the action is performed without any problem. So far so good.
Unfortunately when trying to do the same at robot framework
execute javascript document.getElementsByClassName('table-cell-wrapper')[1].mousedown();
I am getting te following error:
Executing JavaScript:
document.getElementsByClassName('table-cell-wrapper')[1].mousedown();
20131029 12:22:12.445 : INFO : </td></tr><tr><td colspan="3"><img src="selenium-screenshot-1.png" width="800px">20131029 12:22:12.453 : FAIL :
WebDriverException: Message: u'document.getElementsByClassName(...)[1].mousedown is not a function' ;
Then the question is... how can I trigger the event mousedown on a given element using Javascript and Webdriver.
My environment is:
RIDE 1.2.1 running on Python 2.7.5.
Robot Framework 2.8.1
Library Selenium2Library
Library Screenshot
Library Dialogs
Library Collections
Thanks in advance.
From Selenium2Library Execute Javascript keyword:
Note that, by default, the code will be executed in the context of the
Selenium object itself, so this will refer to the Selenium object. Use
window to refer to the window of your application, e.g.
window.document.getElementById('foo')
So you might want to put window. in there.
mousedown() is not a pure Javascript function. JQuery does have one and there is a event called mousedown in plain JS also.
If some element does not exists after the page is loaded causing
Click Element foobar
to fail, you can use Wait Until Page Contains Element and then click that element. You could write your own Press Element keyword to make it more usefull:
Press Element ${locator}
Wait Until Page Contains Element ${locator}
Click Element ${locator}
Im trying to accelerate the use of a web application using selenium Webdriver by creating hotkeys for it. I want certain webdriver click events to be associated with keyboard keys. For example, pressing "s" on the keyboard will click on the submit button.
I understand how to do the clicking and locating elements with webdriver but don't know how to go about listening to the keys from Java while Firefox is open (from a webdriver get call). My application has no GUI and since it's opening a firefox window it will lose focus so KeyListener is not an option.
I have come accross the JNI library that I'm looking into. Any other suggestions how I may do this?
In that case, it is almost always better idea to automate the whole process
Say, you need to daily update salary of the employees. It is better idea to invest your time to read XLS file (almost standard way how those data are delivered to the people destined to do the repetitive work) and read line by line and somehow enter it to the application.
I know I did not provide you the answer you were expecting, but try to think of automating the whole process. It might be little tricky, but doable - and at the end faster - than simple mapping of the keys