How to press Ctrl+A to select all content in a page by Selenium WebDriver using Java

前端 未结 2 1531
遇见更好的自我
遇见更好的自我 2020-12-03 13:43

I want to select all content by pressing Ctrl+a from keyboard by using WebDriver with Java. I wrote the following code:

Actions actionO         


        
相关标签:
2条回答
  • 2020-12-03 14:25

    To Select whole page:

    driver.findElement(By.xpath("//body")).sendKeys(Keys.chord(Keys.CONTROL, "a"));
    

    cssSelector is faster than xpath. So it could be done by using CSSPath also. Below is the way:

    driver.findElement(By.cssSelector("body")).sendKeys(Keys.chord(Keys.CONTROL, "a"));
    
    0 讨论(0)
  • 2020-12-03 14:27

    Have you tried to chord the Ctrl+A keys? The code below is working in my case:

    element.sendKeys(Keys.chord(Keys.CONTROL, "a"));
    
    0 讨论(0)
提交回复
热议问题