What are the advantages of using Selenium Edgedriver's Send Keys to select all and copy text?

Being a novice to using Selenium, I'm exploring this auxiliary library for the first time in VBA.

I've opted to use the Web Driver for Microsoft Edge, and I'm encountering challenges with implementing send keys. Specifically, I am trying to select the entire contents of a page and then copy them to the clipboard.

Below is my current attempt:

'''

 Sub Send_Keys_CTRL_A_Ctrl_C()

     Dim obj As New WebDriver

     obj.Start "edge", ""
     obj.Get "http://www.google.com"
     Application.Wait (Now + TimeValue("0:00:01"))
     obj.FindElementByClass("body").SendKeys (Keys.Control + "a" + 
     Keys.Control)

End Sub

'''

It's evident that the script encounters errors on the last line, which was essentially copied from my IE driver implementation. Thus, it's not surprising that it fails to work seamlessly.

Any assistance would be appreciated. Thank you.

Answer №1

To utilize this code, you need to execute

pip install undetected-chromedriver
. However, it can also be used with normal selenium and edgedriver setups.

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

import undetected_chromedriver as uc
options = uc.ChromeOptions()
options.headless = False
driver = uc.Chrome(options=options)

WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body'))).send_keys(Keys.CONTROL, 'a') #press ctrl + a
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body'))).send_keys(Keys.CONTROL, 'c') #press ctrl + c

Alternatively, you can simply use print(driver.page_source) to retrieve the entire page content.

Although I'm unfamiliar with VBA, the process in Python is outlined above.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble executing the protractor configuration in gulp due to a connection issue with ECONNREFUSED with the address 127.0.0.1:4444

My code works perfectly when I run selenium separately. However, my goal is to start webdriver within gulp but I am encountering the following error: Error code: 135 [12:48:27] E/launcher - Error message: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444 ...

ChromeDriver initialized by Selenium remains active in the background

Having trouble completely deleting a project due to the chromedriver instance running in the background despite no code execution. Please refer to the image linked below: https://i.stack.imgur.com/bt1Tb.png Error encountered during project deletion:https: ...

Error: The absence of a Firefox profile in Python's Selenium causing

Currently, I am facing challenges while attempting to set up a Firefox driver with Selenium. The process of creating the driver seems to be causing some obstacles. My initial attempt looks like this: from selenium import webdriver driver = webdriver.Fire ...

The "Login" button with the ID "loginbutton" and name "login" cannot be clicked at the coordinates (600, 341). It seems there is an issue with clicking on the login button on Facebook

from selenium import webdriver from selenium.webdriver.common.keys import Keys import time PATH = "/Users/khizarm/Downloads/chromedriver" chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("--incognito") drive ...

Unable to execute AndroidDriver on virtual android device using Selenium

Attempting to utilize an Android driver within Selenium has presented a perplexing error that leaves me stumped. I have both an operational Appium Server and an active Android Emulator (from Android Studio) identified as "emulator-5554" when queried with " ...

The ChromeDriver detects when the Chrome browser is launched

When attempting to use selenium chromedriver in Python for the website www.mouser.co.uk, it is immediately flagged as a bot. Does anyone have an explanation for this? Below is the code I am utilizing: https://i.stack.imgur.com/g3uLP.png options = Options ...

Lambda Expressions in WebdriverWait Strategy

I'm seeking a detailed explanation of the Boolean generic type used in ExpectedCondition. Can someone clarify this for me? new WebDriverWait(driver, 60).until((ExpectedCondition<Boolean>) wd->((JavascriptExecutor) wd).executeScript("return d ...

The exception thrown by Runtime.callFunctionOn was due to an error in LavaMoat - the property "Proxy" of globalThis is not accessible in scuttling mode

As I work on developing a Next.js app, I encountered some challenges when trying to run tests with selenium-webdriver. My webapp utilizes authentication with Metamask wallets, and the issue arises when attempting to import a wallet into a test window using ...

Creating an xpath for selecting the calendar element nested inside a td element with specific class and aria-label

I am having difficulty identifying the correct XPath for the element below. <td class="_1dmyat7f" role="button" aria-disabled="false" aria-label="Selected start date. Saturday, 31 August 2019" tabindex="0" style="width: 33px; height: 32px;">31</t ...

Encountering an error in the response body while attempting to send body data from an external file using J

I am facing an issue where I need to send data in the request body from an external file within jmeter, but every time I attempt to do this, I receive an ERR in the response body. Below is my post method request body: ${__FileToString(/Users/public/${__eva ...

Tips for recognizing the initial element in a table with Selenium

wait.until(EC.presence_of_element_located((By.XPATH, "//table//tbody//tr//a[@data-refid='recordId'][0]"))) driver.implicitly_wait(20) line_item = driver.find_elements("xpath", "//table//tbody//tr//a[@data-refid='reco ...

Implementation of Logical name for Selenium WebElement

Is there a known implementation or pattern for retrieving the "Logical Name" of a Selenium WebElement object in Java? I am interested in something along these lines: @FindBy(xpath = "//tr[2]/td[@class='listrow1'][3]") private WebElement txt ...

When using Python Selenium, the driver.close() method may result in an error stating "no such window: target window already closed; web view not found" when attempting to close a new tab

Recently, I've delved into working with multiple tabs in Selenium and encountered a peculiar issue. When running the following code: WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(2)) driver.switch_to.window(driver.window_handles[-1]) time ...

Issue encountered while utilizing WebDriverWait with the ExpectedCondition function presenceOfElementLocated()

I encountered an error while compiling: public static WebDriverWait wait = null; wait = new WebDriverWait(driver, 120); wait.until(ExpectedConditions.presenceOfElementLocated(By.id(HomeScreen.tabHome_ID))); I am currently working with IntelliJ IDE. Err ...

Popup text alert remains persistent in SeleniumPlus test on Internet Explorer

Currently, I am using a method called VerifyAndDismissAlert() in an automated test. try{ WebDriver WD = WebDriver(); Alert alert = WD.switchTo().alert(); alert.accept(); String alertText = alert.getText(); Pause(1); ...

Using unique headers with Phantomjs in Selenium WebDriver

As per the information provided here, it is now feasible to modify headers. Currently, I am attempting to adjust the Accept-Language in the PhantomJS webdriver. The code snippet below does not seem to be effective: DesiredCapabilities.PHANTOMJS['phan ...

Python - ExceptionalInputRequirement

I'm diving into the world of web scraping, but I keep running into roadblocks whenever I attempt to access a URL. Here's the code I'm working with: from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = w ...

Why is a cast required to the generic type in this particular method, whereas similar methods do not require it?

I encountered an issue with a method that requires a generic return type, resulting in the following error: Description Resource Path Location Type Type mismatch: cannot convert from PageTypeOne to P SecuredPage.java To resolve this error, I ha ...

The problem of referencing a stale element and refreshing the DOM with explicit/implicit waits

After experiencing an issue that I was able to resolve using explicit wait, I found myself questioning the inner workings of Selenium WebDriver. It's puzzling how applying an implicitly wait for 300 seconds continued to result in a stale element refer ...

Encountering a StaleElementReferenceException when attempting to interact with buttons in a dynamically updated table using Python with Selenium Webdriver

Encountering a StaleElementReferenceException while testing a webpage with a table is proving to be a challenge. The table includes points and the status of two Blocking points, each with toggle state buttons for 'Yes' and 'No'. The st ...