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
Related
selenium web driver: how to enable mouse move to target elements before clicking or input values?
Mouse is not moved. How to enable it? It should be default behavior for simulating human-machine interaction.
We have so many places for entering values and clicking elements.
The Webdriver implementation does not rely on the actual mouse. It uses low-level browser implementation (through browser native automation drivers like chromedriver or geckodriver) to emulate the mouse interactions. If you take a look at the Webdriver spec, you can see that mouse interactions mention "firing events on nodes" and not actually triggering the mouse itself.
This implementation allows for tests to be run in parallel and/or in headless mode.
So if you call an API like "findSomeElement" and then "click", the result in the browser will be the same as if you had moved your mouse to the element and clicked. Except that your actual mouse pointer won't have moved an inch :)
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.
When opening the print page in Firefox a print dialog is triggered. As is mentioned in the answer linked here (How to handle print dialog in Selenium?), Selenium's WebDriver cant handle these sorts of browser (or OS) dialogs.
Im using Selenium with Java to test a particular website. So I included the following code (as was suggested by the answer linked above) which employed the use of Java Robot to get rid of the print dialog.:
// press Escape programatically - the print dialog must have focus, obviously.
Robot r = new Robot();
r.keyPress(KeyEvent.VK_ESCAPE);
r.keyRelease(KeyEvent.VK_ESCAPE);
This answer made sense to me because when I manually pressed the escape key, the print dialog was dismissed.
Unfortunately, the code mentioned above did not work for me i.e. the print dialog remained there. As suggested by some other posts, I made sure to wait until the print dialog appeared.
While running the automated test code I'm not entirely sure whether "the print dialog was focused" (as is mentioned in the comment in the code given above). I tried multiple methods to get it "in focus" such as switching to the last web handle, switching to the browser alert etc and all of those threw errors. This further confirmed to me the idea that selenium was unable to handle this dialog. I do suspect that the lack of "focus" on the print dialog is where I'm running into the issue.
I want to be able to dismiss this modal because I open the print page multiple times during my testing run which means that multiple print dialogs open. Once the testing code is completed, the browser quits and only one of these dialogs is closed. Could you please help me figure out what I'm doing wrong?
Im using the following:
Geckodriver version: geckodriver-v0.26.0-macos
Java: 1.8.0_191
MacOS: Version 10.15.5 (19F101)
Firefox version: 78.0.2
Please do let me know what other information I could include to help you answer this. Thanks! I would have commented on the thread I mentioned, but Im new to StackOverflow and you need 50 reputation points to make a comment :(
enter image description hereThere is a scenario that I am trying to automate through selenium webdriver (Java) and facing trouble. Print preview is not accessible through selenium as it is within shadow-root. Our task is to download the pdf files from web portals. When we clicked on print button on web, print preview window is opened and we need to click on save button in this print preview window in order to download the pdf. And also linked the URLs of the solutions that I have tried to solve this problem. for screenshot enter image description here
https://www.seleniumeasy.com/selenium-tutorials/accessing-shadow-dom-elements-with-webdriver
How to interact with the elements within #shadow-root (open) while Clearing Browsing Data of Chrome Browser using cssSelector
Handle Print Preview window using selenium in chrome latest version
How can I tell Selenium to press cancel on a print popup?
Selenium how to click Ctrl + p
How to click on the print button on a web page using Selenium
Try with mouse / keyboard actions libraries :
Library pyautogui
Library ImageHorizonLibrary
Check keywords :
pyautogui.Key Down 'enter'
ImageHorizonLibrary.Press Combination Key.enter
The above libraries have additional keywords that should help.
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!