Jump to content

[SOLVED]Paste text from website to notepad/excel


Recommended Posts

Hi, I'm sure that this is a simple question regarding webdriver udf but my search on the forum did not result in the exact same scenario that I need. I will adapt it to my corporate needs but at first I want it to work with an example everybody can reproduce if needed.

I navigate to https://www.daysoftheyear.com/ and want to find out what special day today is. Using the following Code returns the wanted text that today is 'shark awareness day' in the console but it is not pasted in notepad as it is not copied as it probably should be.

#include "wd_core.au3"
#include "wd_helper.au3"

Local $sDesiredCapabilities, $sSession, $sID
_WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe")
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}'

_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)

    _WD_Navigate($sSession, "https://www.daysoftheyear.com/?timezone_offset=nan")
    _WD_LoadWait($sSession)
  Sleep(3000)
  
Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[2]/header/div/div[1]/div/div[2]/h3/a")
_WD_ElementAction($sSession, $sElement, 'text')
ClipGet()
Run("notepad.exe")
Sleep(500)
Send("^v")

Scite returns this, therefore the text has been found but the last mile to paste it to notepad or excel does not work for me.

__WD_Get: URL=HTTP://127.0.0.1:9515/session/b72166b774d7fefb258b3721fc1d4306/element/657e6b5d-31a9-46a8-85c4-acb7f72bf659/text
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"Shark Awareness Day"}...
_WD_ElementAction: {"value":"Shark Awareness Day"}...

Thanks in advance! 

 

Edited by Langmeister
Issue solved
Link to comment
Share on other sites

I have no experience with the functions you are trying to use here but I can see that you have not pushed anything into the clipboard buffer for ClipGet() to retrieve. From what i can see you should probably use ClipPut($sResponseText) after it has been filled.

Phil Seakins

Link to comment
Share on other sites

Here a another (better ?) way than copy/paste :

#include "..\WebDriver\wd_core.au3"
#include "..\WebDriver\wd_helper.au3"

Local $sDesiredCapabilities, $sSession, $sID
_WD_Option("Driver", "..\WebDriver\chromedriver.exe")
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}'

_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "https://www.daysoftheyear.com/?timezone_offset=nan")
 _WD_LoadWait($sSession)
Sleep(3000)

Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[2]/header/div/div[1]/div/div[2]/h3/a")
$sText = _WD_ElementAction($sSession, $sElement, 'text')
Run("notepad.exe")
Local $hWnd = WinWaitActive ("[CLASS:Notepad]")
Local $hCtrl = ControlGetHandle ($hWnd, "", "Edit1")
ControlSetText ($hWnd, "", $hCtrl, $sText)

 

Link to comment
Share on other sites

Does exactly what I was searching for, thanks a lot!
Thanks for your efforts too @pseakins

11 minutes ago, Nine said:

Here a another (better ?) way than copy/paste :

#include "..\WebDriver\wd_core.au3"
#include "..\WebDriver\wd_helper.au3"

Local $sDesiredCapabilities, $sSession, $sID
_WD_Option("Driver", "..\WebDriver\chromedriver.exe")
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}'

_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "https://www.daysoftheyear.com/?timezone_offset=nan")
 _WD_LoadWait($sSession)
Sleep(3000)

Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[2]/header/div/div[1]/div/div[2]/h3/a")
$sText = _WD_ElementAction($sSession, $sElement, 'text')
Run("notepad.exe")
Local $hWnd = WinWaitActive ("[CLASS:Notepad]")
Local $hCtrl = ControlGetHandle ($hWnd, "", "Edit1")
ControlSetText ($hWnd, "", $hCtrl, $sText)

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...