[英]How to press Ctrl+A to select all content in a page by Selenium WebDriver using Java
I want to select all content by pressing Ctrl + a from keyboard by using WebDriver with Java.我想通过使用带有 Java 的 WebDriver 从键盘上按Ctrl + a来 select 所有内容。 I wrote the following code:
我写了以下代码:
Actions actionObj = new Actions(driver);
actionObj.keyDown(Keys.CONTROL)
.sendKeys(Keys.chord("A"))
.keyUp(Keys.CONTROL)
.perform();
Unfortunately, it did not work.不幸的是,它没有用。 What's the wrong in my WebDriver Java code?
我的 WebDriver Java 代码有什么问题?
I want to select all content by pressing Ctrl + a from keyboard by using WebDriver with Java.我想通过在Java中使用WebDriver从键盘上按Ctrl + a来选择所有内容。 I wrote the following code:
我写了以下代码:
Actions actionObj = new Actions(driver);
actionObj.keyDown(Keys.CONTROL)
.sendKeys(Keys.chord("A"))
.keyUp(Keys.CONTROL)
.perform();
Unfortunately, it did not work.不幸的是,它没有用。 What's the wrong in my WebDriver Java code?
WebDriver Java代码有什么问题?
I want to select all content by pressing Ctrl + a from keyboard by using WebDriver with Java.我想通过在Java中使用WebDriver从键盘上按Ctrl + a来选择所有内容。 I wrote the following code:
我写了以下代码:
Actions actionObj = new Actions(driver);
actionObj.keyDown(Keys.CONTROL)
.sendKeys(Keys.chord("A"))
.keyUp(Keys.CONTROL)
.perform();
Unfortunately, it did not work.不幸的是,它没有用。 What's the wrong in my WebDriver Java code?
WebDriver Java代码有什么问题?
Mac users should use Cmnd instead of Control: Mac 用户应该使用 Cmnd 而不是 Control:
element.sendKeys(Keys.chord(Keys.COMMAND, "a"));
Python Python
#! /usr/bin/env python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.service import Service
service_obj = Service(executable_path="C:/Firefox-Webdriver/geckodriver.exe")
browser = webdriver.Firefox(service=service_obj)
browser.get('http://localhost:8000/')
browser.get(url)
body = browser.find_element(By.TAG_NAME, "body")
body.send_keys(Keys.CONTROL + "a")
body.send_keys(Keys.CONTROL + "c")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.