Jump to content

Recommended Posts

Posted
  On 10/18/2022 at 9:09 PM, SkysLastChance said:

thank you so much;

when I finish this script, I will no longer depend on MS Power Automate for my daily task

@hahnhwang

https://www.autoitscript.com/wiki/WebDriver#FAQ #7

You don't need an array in this case. However, 

Local $sElement = _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, '//*[@id="mat-tab-label-0-0"]/div/span/app-number-viewerapp', 100, 5000)
Local $sText = _WD_ElementAction($sSession, $sElement, 'property', 'innerText')

MsgBox(0, "Total", $sText)

 

Expand  

 

  • 4 weeks later...
Posted (edited)

on one PC I get such error:

  Quote

geckodriver.exe: error: Została podjęta próba uzyskania dostępu do gniazda w sposób zabroniony przez
przypisane do niego uprawnienia dostępu. (os error 10013)
geckodriver 0.32.0 (4563dd583110 2022-10-13 09:22 +0000)
WebDriver implementation for Firefox

Expand  

google translate:

  Quote

geckodriver.exe: error: An attempt was made to access a socket in a manner forbidden by
the access rights assigned to it. (os error 10013)
geckodriver 0.32.0 (4563dd583110 2022-10-13 09:22 +0000)
WebDriver implementation for Firefox

Expand  

Anybody hit the problem ?

EDIT: As so far I found:

https://github.com/mozilla/geckodriver/issues/550

https://github.com/mozilla/geckodriver/issues/1208

But in my case it looks like this is not a FIREWALL problem, but I can be wrong.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Found solution.
In order to solve this issue I had to modify _WD_StartUp() by adding --port parameter to the command :

Local $sCommand = StringFormat('"%s" %s ', $_WD_DRIVER, $_WD_DRIVER_PARAMS & " --port=" & $_WD_PORT )

 

EDIT:
Should we add this as a default fix to wd_core.au3 ?

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 11/10/2022 at 12:34 PM, Danp2 said:

@mLipokDon't change _WD_Startup. You should Instead use _WD_Option to add that setting if needed. For example --

$iAltPort = 4567
_WD_Option('DriverParams', '--log trace --port=' & $iAltPort)
_WD_Option('Port', $iAltPort)

 

Expand  

so I suggest to modify _WD_Startup() in this way:

;~  Local $sCommand = StringFormat('"%s" %s ', $_WD_DRIVER, $_WD_DRIVER_PARAMS)
    If Not StringInStr($_WD_DRIVER_PARAMS, "--port") Then $_WD_DRIVER_PARAMS &= " --port=" & $_WD_PORT
    Local $sCommand = StringFormat('"%s" %s ', $_WD_DRIVER, $_WD_DRIVER_PARAMS)

Because if user specify port by this:

_WD_Option('Port', $iAltPort)

then it should be no need to again set the option (port) by this:

_WD_Option('DriverParams', '--log trace --port=' & $iAltPort)

 

I mean it is redundant _WD_Option() usage, because when it is set once, it should be set properly, so this:

_WD_Option('Port', $iAltPort)

should be the only one needed.

 

Can you agree with my reasoning ?

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

@mLipokIf you are not using the default port for webdriver communication, then you must notify the webdriver of the alternate port. This is what is occurring in the 'DriverParams' line.

I understand why you want to make this change. However, I believe that it isn't needed as the vast majority scripts will use the default port number. Also, the following is valid for geckodriver and your change could lead to unexpected results --

_WD_Option('DriverParams', '-p ' & $iAltPort)

This issue has definitely come up previously, so this could make a good FAQ.

Posted (edited)
  On 11/14/2022 at 3:05 AM, jiataifeng said:

Have anyone tried Google calendar? It seems it can not find anything with _WD_FindElement

Expand  

it would return something like this

__WD_Post: URL=HTTP://127.0.0.1:9515/session/147c20d2cde2adb344f3397afad8cda8/element; $sData={"using":"xpath","value":"//div[@role='button']"}
__WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"0ad86d88-d76b-4640-a895-43ec547b02b3"}}
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"0ad86d88-d76b-4640-a895-43ec547b02b3"}}

 

is the page source code encrypted? It seems what the program gets is not what we see in f12 developing window.

 

@Danp2any comments? please help, thanks.

Edited by jiataifeng
Posted
  On 11/14/2022 at 3:05 AM, jiataifeng said:

Have anyone tried Google calendar? It seems it can not find anything with _WD_FindElement

_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"0ad86d88-d76b-4640-a895-43ec547b02b3"}}

Expand  

The above shows that the element was in fact found. Now you need to do something with it. What's your next step. Do you need to click it, retrieve its value, or something else?

Posted
  On 11/14/2022 at 6:47 PM, Danp2 said:

The above shows that the element was in fact found. Now you need to do something with it. What's your next step. Do you need to click it, retrieve its value, or something else?

Expand  

try to click it. but why it's so different?

  • 3 weeks later...
Posted (edited)

@Danp2

When available, could you take a look of Google Calendar? I don't know how to set the value of the highlighted part, though tried for a very long time. Thank you

test.png

Edited by jiataifeng
Posted

Did you try JS ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 2 weeks later...
Posted

Hello!
Please, help with _WD_FindElement() , parameter $sStartNodeID 
I could not find an example in wd_demo.au3
I am trying to take text from a table, rows have a common class
I use _WD_FindElement and $bMultiple to get an array of string id
Then I try to retrieve cells with text from these rows using $sStartNodeID 

xpath line checked in chrome
Please tell me the syntax of the command in my example
Try $sStartNodeID = '//tr/td[1]/span/text()' , '/tr/td[1]/span/text()' , 'tr/td[1]/span/text()'
'//td[1]/span/text()' , '/td[1]/span/text()' , 'td[1]/span/text()'

#include "wd_capabilities.au3"
#include "wd_helper.au3"
Global $sURL = 'file:///D:/Work/test-table.html' , $WD_SESSION , $sStatus

    _WD_start ()

$idElementS = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, "//tr[contains(@class,'MuiTableRow')]" , Default , True )
    $iSizeOfArray = UBound ($idElementS)

    MsgBox ('','','Number of Rows = ' & $iSizeOfArray)
    For $i = 0 to $iSizeOfArray-1
        $idElem = $idElementS[$i]
        $sTd1 = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, "/tr/td[1]/span/text()" , $idElem )
        $sTd2 = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, "/tr/td[2]/span/text()" , $idElem )
        $sTd3 = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, "/tr/td[3]/span/text()" , $idElem )
    Next

    _WD_DeleteSession($WD_SESSION)
    _WD_Shutdown()

Func _WD_start ()
    ; startup - cleaning internal capabilities JSON object
    _WD_CapabilitiesStartup()
    ; starting with "alwaysMatch" settings
    _WD_CapabilitiesAdd("alwaysMatch")
    _WD_CapabilitiesAdd("acceptInsecureCerts", True)
    ; switching to "firstMatch" with "chrome" which will specify to use "goog:chromeOptions"
    _WD_CapabilitiesAdd("firstMatch", "chrome")
    ; setting vendor specific "goog:chromeOptions" settings
    _WD_CapabilitiesAdd("w3c", True)
    _WD_CapabilitiesAdd("prefs", "download.default_directory", @ScriptDir & "\Downloads")
    _WD_CapabilitiesAdd("excludeSwitches", "enable-automation")
    ; get/assign Capabilities JSON Object content to string
    Local $sCapabilities = _WD_CapabilitiesGet()
    #EndRegion - creating capabilities string
    ; setting WebDriver options
    _WD_Option("Driver", @ScriptDir & "\chromedriver.exe")
    _WD_Option("Port", 9515)
    _WD_Option("DefaultTimeout", 1000)

    ; starting WebDriver with specified options
    _WD_Startup()
    $WD_SESSION = _WD_CreateSession($sCapabilities)
    _WD_Navigate($WD_SESSION, $sURL)
EndFunc

But I always get an error - "Invalid Expression [11]"

_WD_FindElement ==> Invalid Expression [11] : Parameters:   Strategy=xpath   Selector=//tr/td[1]/span/text()   StartNodeID=32f30f9f-e53a-442a-aa6e-3427ea20c286   Multiple=Default   ShadowRoot=Default
....
_WD_FindElement ==> Invalid Expression [11] : Parameters:   Strategy=xpath   Selector=/tr/td[1]/span/text()   StartNodeID=dc0248c3-22ed-4f49-a431-6f0380dfc04b   Multiple=Default   ShadowRoot=Default
...
_WD_FindElement ==> Invalid Expression [11] : Parameters:   Strategy=xpath   Selector=tr/td[1]/span/text()   StartNodeID=17871eb6-5ccf-4bba-9bf9-d015248b9aa8   Multiple=Default   ShadowRoot=Default
...
_WD_FindElement ==> Invalid Expression [11] : Parameters:   Strategy=xpath   Selector=//td[1]/span/text()   StartNodeID=69516889-6e17-4c65-846f-c1c397aeba97   Multiple=Default   ShadowRoot=Default
...
_WD_FindElement ==> Invalid Expression [11] : Parameters:   Strategy=xpath   Selector=/td[1]/span/text()   StartNodeID=5e99e034-ad4b-4f7b-8518-29f0bd26ba34   Multiple=Default   ShadowRoot=Default
...
_WD_FindElement ==> Invalid Expression [11] : Parameters:   Strategy=xpath   Selector=td[1]/span/text()   StartNodeID=5a9d4385-6a54-4160-a5f4-0b02d0a2c0a7   Multiple=Default   ShadowRoot=Default

HTML table in attach.
I am immensely grateful for your help!

 

test-table.htmlFetching info...

Posted

You must use a relative selector when using xpath with a starting node. You also need to obtain the element's text separately.

Instead of this --

$sTd1 = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, "/tr/td[1]/span/text()" , $idElem )

You need to do it like this --

$idElem = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, "./td[1]/span" , $idElem)
        $sContents = _WD_ElementAction($WD_SESSION, $idElem, 'text')

Another option would be to use _WD_GetTable to obtain an array containing the table's contents.

Posted

Danp2 - you are divine!
Thanks for the tip about _WD_GetTable , I used it, but because of the complex cell contents I need individual access to each cell. 
You have solved my problem.
Thank you so much!

Posted

After updating geckodriver.exe to 0.32.0 I'm getting the following error:

__WD_Post ==> Webdriver Exception [10] : HTTP status = 500 ResponseText={"value":{"error":"session not created","message":"Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line","stacktrace":""}}

 

Also, I usually run scripts with SciTE-Lite, but I've been playing around with Notepad++ NppExec as well - - when I run any webdriver related scripts with NppExec I get the following error:

_WD_Startup ==> File issue [18] : Non-existent Web Driver: geckodriver.exe

I don't get this error with SciTE-Lite. What could be the reason? I've only had this issue with anything related to geckodriver.exe. I have geckodriver.exe in PATH.

Posted

@noellarkinIIRC, this occurs with the 32 bit version of Geckodriver. You need to either switch to the 64 bit version or supply the binary location as part of your capabilities string.

  Quote

_WD_Startup ==> File issue [18] : Non-existent Web Driver: geckodriver.exe

Expand  

This feature was added by @mLipokhere. The current implementation requires you to either provide the full path to the webdriver or it must exist in the current working directory. Unsure why it works in one editor and not the other.

Posted

I was able to get it working by moving the geckodriver.exe to the Include folder, as well as using the x64 version. Thanks for clarifying.
However, the SciTE/Notepad++ issue remains, still getting "Non-existent Web Driver: geckodriver.exe " when using NppExec.

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...