I am learning robot framework and all I'm trying is to search for a video but i get stuck on inserting text in search bar, with error:
InvalidElementStateException: Message: Unable to clear element that cannot be edited:
(Error occurs in the very last line of below code)
More specific, I am trying to open Youtube in firefox, (accept the cookies) and then click on search bar, it clicks but the text is not inserted.
what i managed until now:
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${Browser} firefox
${url2} https://www.youtube.com/
*** Test Cases ***
Trololo
ReallyDontOpen #Open Browser
maximize browser window #Maximize windows
# run keyword if Check for Cookies popup Close YoutubeCookies
Close YoutubeCookies #Accept youtube cookies
Search For Magic
#close browser
*** Keywords ***
ReallyDontOpen
open browser ${url2} ${Browser}
Check for Cookies popup #unused until fixing IF statement
wait until element contains xpath:/html/body/c-wiz/div/div/div/div[2]/div[1]/h1 Before accessing YouTube
Close YoutubeCookies
wait until element contains xpath:/html/body/c-wiz/div/div/div/div[2]/div[1]/h1 Before accessing YouTube
click element xpath:/html/body/c-wiz/div/div/div/div[2]/div[1]/div[3]/div[1]/form[2]/div/div/button/span
Search For Magic
click element xpath://*[#id="search-form"]
clear element text xpath://*[#id="search"]
input text xpath://*[#id="search"] rick roll 10 hours
I tried all kind of IDs around that search bar but nothing works...
Thank you in advance!
Replace your last line with this code:
input text xpath://input[#id="search"] rick roll 10 hours
Remove this line no need to clear:
clear element text xpath://*[#id="search"]
Below is my working code
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${Browser} firefox
${url2} https://www.youtube.com/
*** Test Cases ***
Trololo
ReallyDontOpen #Open Browser
maximize browser window #Maximize windows
#run keyword if Check for Cookies popup Close YoutubeCookies
Close YoutubeCookies #Accept youtube cookies
Search For M`enter code here`agic
#close browser
*** Keywords ***
ReallyDontOpen
open browser ${url2} ${Browser}
Check for Cookies popup #unused until fixing IF statement
wait until element contains xpath:/html/body/c-wiz/div/div/div/div[2]/div[1]/h1 Before accessing YouTube
Close YoutubeCookies
wait until element contains xpath:/html/body/c-wiz/div/div/div/div[2]/div[1]/h1 Before accessing YouTube
click element xpath:/html/body/c-wiz/div/div/div/div[2]/div[1]/div[3]/div[1]/form[2]/div/div/button/span
Search For Magic
input text xpath://input[#id="search"] rick roll 10 hours
Related
I want to take screenshot of the entire web page. I have tried using
capture page screenshot
But the problem is that it takes the screenshot only of the visible part of the webpage. I want the screenshot for the whole page.
You have to tinker something for yourself. For example you can setup a loop where you are sending PAGE DOWN keys to the browser to scroll down and take a screenshot after each iterations.
E.g.:
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Take Screenshot
Open Browser https://stackoverflow.com Chrome
FOR ${i} IN RANGE 4
Capture Page Screenshot
Press Keys None PAGE_DOWN
END
[Teardown] Close All Browsers
You have to decide based on your application how many scrolls you need.
I'm using robotframework(3.1.2) with seleniumlibrary(3.3.1) to automate zooming a page with Firefox(69.0.1)/geckodriver(0.25.0).
According to this documentation I thought the keyword Press Keys would be useful, but it seems that the firefox instance is not affected.
Am I missing something essential in how to Send Keys to the browser or is this not working by intention?
I've also been playing around with the style-transform solution, but the result wasn't satisfying - as for example the F11 (fullscreen) won't work this way.
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Zoom Automation
Open Browser https://www.stackoverflow.com Firefox
Maximize Browser Window
# this should increase the zoom to 120%
Press Keys ${None} CTRL+ADD CTRL+ADD
# set firefox to fullscreenmode
Press Keys ${None} F11
# this code zooms the page, but the result is not the expected one (cropped view)
# Execute Javascript document.body.style.MozTransform = 'scale(1.2)'
# Execute Javascript document.body.style.MozTransformOrigin = 'top'
According to the accepted answer, I ended up with this code an it works!
import pyautogui
class keyautomation(object):
ROBOT_LIBRARY_VERSION = 1.0
def __init__(self):
pass
def press_ctrl_add(self):
pyautogui.keyDown('ctrl')
pyautogui.keyDown('add')
pyautogui.keyUp('ctrl')
pyautogui.keyUp('add')
*** Settings ***
Library SeleniumLibrary
Library keyautomation
*** Test Cases ***
Zoom Automation
Open Browser https://www.stackoverflow.com Firefox
Maximize Browser Window
Press Ctrl Add
Press Ctrl Add
You can use pyautogui library in robot framework. This will help to perform mouse and keyboard actions.
Ex for pressing F11:
Keydown f11
Keyup f11
https://pyautogui.readthedocs.io/en/latest/keyboard.html#the-typewrite-function
The issue I'm having is with the command Go Back from the selenium library within RIDE.
I have tried to input the Go Back command into a test script im running. The website should then simulate a click on the back button within the browser (chrome). It however does not seem to work while it does tick off the step as done and passed. I googled some stuff and found out sometimes the browser isnt ready loading when trying to perform the next command and thus it could create an issue. Because of this i tried to implement the Set Selenium Implicit Wait 10 seconds command
In the img link below (can't post the img because im not 10 reputation) you can see that I have the command Go Back and Set Selenium Implicit Wait 10 seconds. Neither however seem to work (notice that while the timer is suppose to wiat 10 seconds. it is marked as completed in 00:00:00.003
https://gyazo.com/fa18566997436989ab5a6503b9064965
I noticed that both come from the seleniumlibrary and while installed and imported (or Close Browser would not work) neither works. I'm not sure what im doing wrong here. In the picture below is how i wrote it down in the testcase.
https://gyazo.com/7d914c7c74999177ae2dca4a02d4a4bb
Any help would be much appreciated into making the bowser use the back button and/or explaining why certain aspects of the seleniumlibrary don't seem to work.
See the implicit wait section. It can be read like "the maximum time when waiting to find the element". When you use the Go Back keyword, there is no element to wait for, so it is immediate.
See here a complete example (that would work as long this question is on the first results page):
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Move Back On Browser
Open Browser https://stackoverflow.com/questions/tagged/robotframework%2bselenium?tab=Active Chrome
Scroll Element Into View xpath=//a[.='Seleniumlibrary command not working with Ride?']/../..//div[contains(#class, 'excerpt')] # Scroll to excerpt, because Cookie Policy ovelay is over URL element
Capture Page Screenshot active_questions.png
Click Link xpath=//a[.='Seleniumlibrary command not working with Ride?']
Capture Page Screenshot target_question.png
Set Selenium Implicit Wait 10 seconds
Go Back
Capture Page Screenshot after_go_back.png
[Teardown] Close Browser
I'm exploring Robot Framework for some smoke testing of a site, and at a point have to sign in, which opens a new window. Moving to the new window with Select Window works for me, but I'm bridging this change by identifying the title of Sign In, and the new window does not immediately adopt that title as it loads your login form - sometimes this takes half a second, sometimes more than 5.
I'm working around this right now by having the test sleep for the obnoxiously long period of 10s, but surely there are more reliable ways of ensuring that I can change my target window to the new one, and not have my test fail and exit while the page is loading. I took a shot at using the redirect url as the identifier, but sometimes it redirects very quickly and fails, or if not, then it gets hung up on the next check for the login field that isn't loaded. I've seen commands like Wait Until Element Is Visible, but unfortunately that doesn't help when I can't target the window where things are loading...
For the sake of it:
*** Test Cases ***
Basic Workflow
Open Browser To Homepage
Go To Sign In
*** Keywords ***
Open Browser To Homepage
Open Browser ${HOMEPAGE} ${BROWSER}
Maximize Browser Window
Set Selenium Speed ${DELAY}
Go To Sign In
Click Button Sign In
Sleep 10s
Select Window Sign In
Title Should Be Sign In
Using Selenium2Library currently.
lauda had it right in writing out a Keyword for managing the Select Window. I found Wait Until Keyword Succeeds and made a keyword for it to wait on.
Go To Sign In
Click Button Sign In
Wait Until Keyword Succeeds 20s 3s Switch To Sign In Page
Title Should Be Sign In
Switch to Sign In Page
Select Window Sign In
Thank you, both!
Recently I've started using Robot with Selenium2Library to automate some GUI test cases. One of the application I'm automating is ReviewBoard.
So far I've been able to automate some stuff but having a lot of problem with inputting text into text area. An example would be the description field on reviewboard.
My latest attempt is
:FOR ${URL} in #{URL_LIST}
\ Go To ${URL}
# Enter team reviewer name and press ok
\ Click Element xpath=//*[#id="fieldset_reviewers_body"]/tr[2]/td/a/div[#class="rb-icon rb-icon-edit"]
\ Input Text xpath=//*[#id="fieldset_reviewers_body"]/tr[2]/td/form/input rbtest_teamreviewer1
\ Press Key xpath=//*[#id="fieldset_reviewers_body"]/tr[2]/td/form/input \\9
\ Click Element xpath=//*[#id="fieldset_reviewers_body"]/tr[2]/td/form/span/input[#class="save"]
# Fill out Testing Done field
\ Click Element xpath=//*[#id="review_request_main"]/div[2]/label/a/div[#class="rb-icon rb-icon-edit"]
\ Press Key xpath=//*[#id='review_request_main']/div[2]/div/form/*//textarea Testing Done
\ Click Element xpath=//*[#id="review_request_main"]/div[2]/div/form/div[2]/input[#class="save"]
However, I'm receving the exception
ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
Stacktrace:
at fxdriver.preconditions.visible (file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/command-processor.js:10092)
at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/command-processor.js:12644)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/command-processor.js:12608)
I've try different ways such as using Input Text instead of Press Key but having similar problem...I don't have any problem when type is input.
Does anyone have any idea how I might be able to solve this?
If you are interested, you can view the demo reviewboard at http://demo.reviewboard.org/r/1502/ with username:guest6317 password:demo
CodeMirror replaces the textarea with its own object. This object has methods for interacting with the widget. However, in the case of reviewboard this object isn't initialized until you click on the textarea. So, the solution is going to look like this:
find and click on the textarea
find the reference to the CodeMirror editor object
use CodeMirror methods to interact with the editor widget
Step 1: clicking on the text area
The first step is to click on the textarea in order to initialize the widget. This can be done easily with the "Click Element" keyword:
click element id=field_description
Step 2: get a reference to the editor object
The reviewboard developers probably have a reference to the object, so you could ask them for the name of the variable. However, we can create our own variable for testing purposes. CodeMirror adds a CodeMirror attribute on the div that contains the editor so can use this information to save a reference to a temporary javascript variable:
Execute javascript
... _editor = document.querySelectorAll("div.CodeMirror")[0].CodeMirror;
Step 3: interacting with the editor
The CodeMirror editor has many methods for interacting with the contents of the editor. For example, if you want to replace the contents with your own string, you can call the setValue method.
For example, to replace all of the data with "Hello world!" you could do this:
execute javascript _editor.setValue("Hello world!");
Step 4: putting it all together
Here is a complete test script that replaces the contents of the editor with "Hello world", and then pauses so you can verify that it worked. I tested this on a linux system with chrome and firefox.
*** Variables ***
${ROOT} http://demo.reviewboard.org
${BROWSER} chrome
${USERNAME} guest6317
${PASSWORD} demo
*** Settings ***
Library Selenium2Library
Library Dialogs
Suite Setup open browser ${ROOT} ${BROWSER}
Suite Teardown close all browsers
*** Test Cases ***
Example
[Setup] run keywords
... Log in
... AND go to ${ROOT}/r/1502/
click element id=field_description
Execute javascript
... _editor = document.querySelectorAll("div.CodeMirror")[0].CodeMirror;
... _editor.setValue("Hello world!");
pause execution
*** Keywords ***
Log in
go to ${ROOT}/account/login
input text id=id_username ${USERNAME}
input text id=id_password ${PASSWORD}
submit form