[英]Zoom In and Zoom out using selenium
I have a requirement, where I need to perform Zoom In and Zoom out using selenium webdriver. 我有一个要求,我需要使用Selenium Webdriver执行放大和缩小。 So this is the short cut key that i need to perform. 这是我需要执行的快捷键。 Control+Shift+Add
Key. Control+Shift+Add
键。
I tried the below code in chrome browser. 我在chrome浏览器中尝试了以下代码。 But unable to perform action. 但是无法执行动作。 Could anyone have the right solution? 谁能找到合适的解决方案?
Actions actions = new Actions(driver);
actions.keyDown(Keys.CONTROL).keyDown(Keys.SHIFT).sendKeys(Keys.chord(Keys.ADD)).keyUp(Keys.CONTROL).keyUp(Keys.SHIFT).perform();
Chrome Version - 62 Chrome版本-62
Selenium Version - 2.53 硒版本-2.53
OS - Windows 7 and 10 操作系统-Windows 7和10
If you want to do the zoom in chrome (not with the css) you can use the API. 如果要进行Chrome缩放(不使用CSS),则可以使用API。 For example: 例如:
driver.get('chrome://settings/')
driver.execute_script('chrome.settingsPrivate.setDefaultZoom(1.5);')
driver.get("https://www.google.co.uk/")
EDIT 编辑
In Java: 在Java中:
System.setProperty("webdriver.chrome.driver", /pathTo/chromeDriver);
ChromeDriver driver = new ChromeDriver();
driver.get("chrome://settings/");
driver.executeScript("chrome.settingsPrivate.setDefaultZoom(1.5);");
driver.get("https://www.google.co.uk/");
You can use javascript to do this action (using css zoom): 您可以使用javascript来执行此操作(使用CSS缩放):
For example (in python): 例如(在python中):
driver.execute_script("document.body.style.zoom = '200%'")
It works at least with Chrome. 它至少与Chrome兼容。
如果您使用的是无头镀铬,则可以添加--force-device-scale-factor=1.5
参数来更改缩放级别
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.