如何提供键盘组合(Shift +命令+ F)以使谷歌Chrome全屏显示

时间:2014-09-08 09:08:15

标签: python selenium

需要在使用Selenium Python打开时将Google Chrome打开至全屏

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get("http://google.com")

2 个答案:

答案 0 :(得分:0)

试试这个:

driver = webdriver.Chrome()
driver.get("http://google.com")
actions = ActionChains(driver)
actions.key_down(Keys.SHIFT).send_keys('f').key_up(Keys.SHIFT).perform()

答案 1 :(得分:0)

(1)使用动作类: -

Actions builder = new Actions(driver);
builder.keyDown(Keys.CONTROL).click(driver.findElement(locator)).keyUp(Keys.CONTROL).build().perform();

(2)使用机器人类

Robot r=new Robot();
r.keyPress(KeyEvent.VK_SHIFT);
r.keyPress(KeyEvent.VK_META);
r.keyPress(KeyEvent.VK_F);

r.keyRelease(KeyEvent.VK_SHIFT);
r.keyRelease(KeyEvent.VK_META);
r.keyRelease(KeyEvent.VK_F);

(3)使用Keys类

Keys.chord(Keys.CONTROL, "a"); [Form your OWN]