How to change zoom of page using robot framework

6,310 views
Skip to first unread message

roger referabal

unread,
Dec 10, 2014, 3:02:37 PM12/10/14
to robotframe...@googlegroups.com

I want to decrease the zoom of the page to 80% at the start of a function, then perform some actions and then reset the zoom back to 100%. I am trying the following to decrease the zoom but its not working:

Press Key    |  xpath=//*[.='xyz']     |   17     | # Press Control
Press Key    |  xpath=//*[.='xyz']     |   45     | # Press minus key
Press Key    |  xpath=//*[.='xyz']     |   45     | # Press minus key

I guess what my code does is to send the keys one by one whereas it should send the keys all together. I am using Robot Framework and RIDE. I am trying to do the above for FireFox in Windows.

Also kindly guide me what library should I import if I want to use Press Key Native.

Tatu Aalto

unread,
Dec 11, 2014, 1:52:01 AM12/11/14
to mcont...@gmail.com, robotframework-users

Ugh

I assume that we are talking about the Selenium2Library (Python). And your assumption is correct, it is sending the keys as independent events and therefore zoom doesn't work.

The bad news is that there is not keyword to do that. But there's a workaround available, but please note that changing the zoom level something else than 100% will most likely cause the selenium to interact with wrong elements.

Basically you need to write your own library keyword [1] to change the zoom, by extending the existing [2] Selenium2Library functionality. You need to get the driver object from the Selenium2Library and execute the code in below in your keyword.

driver.find_element(By.tag_name("html")).send_keys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT))

Please note that all the code is untested and comes out of my memory, so it most likely contains errors.

But it should provide you an idea how one can do it. Feel free to ask more questions, if you do not get it working, because the example I provided is quite theoretical.

-Tatu
Send from my mobile
[1] http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-test-libraries 
[2] http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#extending-existing-test-libraries

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Nuno Rodrigues

unread,
Jul 10, 2017, 5:01:58 PM7/10/17
to robotframework-users, mcont...@gmail.com
Hello,
Without performing coding extensions nor pressing Keys and via RobotFramework, you can try the CSS way
Execute javascript  document.body.style.zoom="70%"
sleep 3 
#reset:
Execute javascript  document.body.style.zoom="0%"

 Hope it can still be usefull
BR
Nuno
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages