简体   繁体   English

如何通过 Selenium WebDriver 使用 Java 按 Ctrl+A 到 select 页面中的所有内容

[英]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.

相关问题 如何使用 Java 在 selenium WebDriver 中按 CTRL+T 和 CTRL+TAB? - How to press CTRL+T and CTRL+TAB in selenium WebDriver using Java? 使用 java 在 Selenium WebDriver 中按下(Ctrl + 鼠标单击) - Key press in (Ctrl + mouse click) in Selenium WebDriver using java 如何使用Selenium WebDriver按Ctrl + 0(零) - How to press Ctrl+0 (Zero) using Selenium WebDriver 按 Ctrl+Shift+c 使用 Selenium webdriver 不工作 - Press Ctrl+Shift+c using Selenium webdriver is not working 如何使用 Java 在 Selenium 中按 Ctrl + Shift - How to press Ctrl + Shift in Selenium with Java 如何使用Java在Selenium WebDriver中按“TAB”然后按“ENTER”键? - How to press “TAB” then “ENTER” key in Selenium WebDriver using Java? 如何使用Java在Selenium WebDriver中按“ALT + S” - How to press “ALT+S” in Selenium WebDriver using Java 选择SWT文本字段中不存在的所有(CTRL + A)选项 - Select all (CTRL+A) option not present in SWT Text field 无法使用Java和Selenium Webdriver单击网页上的所有链接 - Not able to click all links on a web page using Java and Selenium Webdriver 当元素不是选择类型输入时,如何使用Selenium Webdriver Java从下拉列表中获取所有选项值? - how to get all option values from dropdown using selenium webdriver java when the element is not a select type input?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM