Jump to content

WebDriver UDF - Help & Support (IV)


Recommended Posts

I haven't used NppExec, so I can't provide much guidance there. I can only speculate that something is different in the way that it launches AutoIt. Have you checked the working directory in each scenario?

To use an alternative browser, you will need to supply the binary location of the browser executable as part of your capabilities string.

Link to comment
Share on other sites

  • 2 weeks later...

I had read your Web Driver, but did not see detail guide, i have some questions please answer them for me:

I want to clear then fill value in input. I knew that i miss many thing in this code, i'm newbie

Autoit:

Func _Run()

   $sSession = _WD_CreateSession(Default)
   ; Locate a single element
   ; (Global Const $sElementSelector = "//input[@class='UserName']")
   $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sElementSelector)

   _WD_ElementAction($sSession, $sElement, 'clear')
   Sleep(500)
  
   _WD_ElementAction($sSession, $sElement, 'value', "testing 123")
   Sleep(500)
   
EndFunc

Html:

<input class="UserName" id="LoginExtender_txtUserName" onkeypress="$find('LoginExtender')._keypress(this, event);" autocomplete="off" style="width: 275px">

Then get this:

__WD_Post ==> Send / Recv error [6] : HTTP status = 0
_WD_CreateSession ==> Webdriver Exception [10]
__WD_Post ==> Send / Recv error [6] : HTTP status = 0
_WD_FindElement ==> Send / Recv error [6] : Parameters:   Strategy=xpath   Selector=//input[@class='UserName']   StartNodeID=Default   Multiple=Default   ShadowRoot=Default
__WD_Post ==> Send / Recv error [6] : HTTP status = 0
_WD_ElementAction ==> Send / Recv error [6] : Parameters:   Command=clear   Option=Default
__WD_Post ==> Send / Recv error [6] : HTTP status = 0
_WD_ElementAction ==> Send / Recv error [6] : Parameters:   Command=value   Option=<masked>

 

Edited by iSan
Noob question
Link to comment
Share on other sites

I got Error: Check logs. I only test for DemoElements

image.png.919ede18af6ce280eb02704ce8974e9d.pngimage.png.d20ac9f5f015b4ec9eaa7d6ba1226af7.png

@Danp2 I'm sorry, i mean that i use only Browser: Chrome and i wanna find, clear, input or click to an Element. 

I know that i can use _WD_FindElement, _WD_ElementAction

But i'm getting confuse, how to SetChrome as default.

Ex Demo: Default browser is Chrome then DemoElemnts

Is that understandable? Sorry for my bad English

Link to comment
Share on other sites

@iSan If you check the scite output panel,  you will find the reason for the check logs message.  it's probably because you haven't downloaded chromedriver. The script will download it for you if you choose the correct option from the Update drop down.

For your own script, you should be able use the SetupChrome routine from wd_demo.

Link to comment
Share on other sites

Oh. The script actually download it for me, i can rune Demo now.

But what does Headless (Yes/No) do? Can i skeep it and set Headless = False

23 minutes ago, Danp2 said:

For your own script, you should be able use the SetupChrome routine from wd_demo.

Yeah, i'm keep going on it, i think i need time. I just to excited, ask while didn't research enough

Edited by iSan
Link to comment
Share on other sites

Hi @iSan,

18 minutes ago, iSan said:

[...] But what does Headless (Yes/No) do? Can i skeep it and set Headless = False [...]

yes you can skip this setting (keep it to False), otherwise you will not see what your browser automation doings will do (or not do) 😅 .

 

18 minutes ago, iSan said:

[...] Yeah, i'm keep going on it, i think i need time. I just to excited, ask while didn't research enough [...]

Please have a look at the README file of the project to get more information and to get more into the WebDriver approach. I'm sure this will help you a lot. Also get in touch with the Tutorial/Wiki page of the project. There are several answered question which will help you 😀 .

It would also be helpful when you talk about what are you trying to do? I noticed you want to clear and fill a input. Are you able to navigate to the page and are you able to use locators/selectors like XPath or CSS Selector etc.? If not, I recommend you to learn more about that before.

Please provide that much information as you can. Then it's probably that we can support you on your way of browser automation 🤝 .


Best regards
Sven

________________
Stay innovative!

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

Try to build my scrip:

; non standard UDF's
#include "wd_helper.au3"
#include "wd_capabilities.au3"
#include "wd_core.au3"
#EndRegion - include files

Local  $sCapabilities, $sSession

_SetupChrome()

_WD_Startup()
$sSession = _WD_CreateSession($sCapabilities)
_WD_Navigate($sSession, 'https://www/youtube.com')
_WD_SetInputValue($sSession, "//input[@id='search']", 'test input')
_WD_ClickElement($sSession, "//button[@id='search-icon-legacy']")

Func _WD_SetInputValue($sSession, $xPath, $Value)
    $Element = _WD_FindElement($sSession, 'xpath', $xPath)
    _WD_ElementAction($sSession, $Element, 'value', $Value)
EndFunc

Func _WD_ClickElement($sSession, $xPath)
    $Element = _WD_FindElement($sSession, 'xpath', $xPath)
    _WD_ElementAction($sSession, $Element, 'Click')
EndFunc

Func _SetupChrome()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')
    Local $sCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args": [ ' & """start-maximized""," & " ""disable-infobargs""" & "" & ']}}}}'
EndFunc

I don't know where i got trouble, try to find in wd_core.au3 or wd_helper.au3 but still do not understand, somewhere around _WD_Post and _WD_CreateSession

_WD_Option ==> Success [0] : Parameters:   Option=Driver   Value=chromedriver.exe
_WD_Option ==> Success [0] : Parameters:   Option=Port   Value=9515
_WD_Option ==> Success [0] : Parameters:   Option=DriverParams   Value=--log-path="C:\Users\User\Desktop\Autoit\WebDriver\au3WebDriver-0.11.0\chrome.log"
_WD_IsLatestRelease ==> Success [0] : True
_WD_Startup: OS:    WIN_10 WIN32_NT 19044 
_WD_Startup: AutoIt:    3.3.16.0
_WD_Startup: Webdriver UDF: 0.11.0 (Up to date)
_WD_Startup: WinHTTP:   1.6.4.1 (Download latest source at <https://raw.githubusercontent.com/dragana-r/autoit-winhttp/master/WinHttp.au3>)
_WD_Startup: Driver:    chromedriver.exe (32 Bit)
_WD_Startup: Params:    --log-path="C:\Users\User\Desktop\Autoit\WebDriver\au3WebDriver-0.11.0\chrome.log"
_WD_Startup: Port:  9515
_WD_Startup: Command:   "chromedriver.exe" --log-path="C:\Users\User\Desktop\Autoit\WebDriver\au3WebDriver-0.11.0\chrome.log" 
_WD_Startup ==> Success [0]
__WD_Post ==> Invalid argument [5] : HTTP status = 400
_WD_CreateSession ==> Webdriver Exception [10]
__WD_Post ==> Invalid session ID [15] : HTTP status = 404
_WD_Navigate ==> Invalid session ID [15] : Parameters:   URL=https://www/youtube.com
__WD_Post ==> Invalid session ID [15] : HTTP status = 404
_WD_FindElement ==> Invalid session ID [15] : Parameters:   Strategy=xpath   Selector=//input[@id='search']   StartNodeID=Default   Multiple=Default   ShadowRoot=Default
__WD_Post ==> Invalid session ID [15] : HTTP status = 404
_WD_ElementAction ==> Invalid session ID [15] : Parameters:   Command=value   Option=<masked>
__WD_Post ==> Invalid session ID [15] : HTTP status = 404
_WD_FindElement ==> Invalid session ID [15] : Parameters:   Strategy=xpath   Selector=//button[@id='search-icon-legacy']   StartNodeID=Default   Multiple=Default   ShadowRoot=Default
__WD_Post ==> Invalid session ID [15] : HTTP status = 404
_WD_ElementAction ==> Invalid session ID [15] : Parameters:   Command=Click   Option=Default

 

Link to comment
Share on other sites

27 minutes ago, iSan said:

_WD_Startup: WinHTTP:   1.6.4.1 (Download latest source at <https://raw.githubusercontent.com/dragana-r/autoit-winhttp/master/WinHttp.au3>)

Please update your WinHTTP source using the link above.

Quote

__WD_Post ==> Invalid argument [5] : HTTP status = 400 _
WD_CreateSession ==> Webdriver Exception [10]

Your attempt to create a session is failing. It appears that you are declaring $sCapabilities local to SetupChrome, so the value assigned is lost once that function exits.

Link to comment
Share on other sites

@Danp2 I'm using WinHTTP:   1.6.4.1 now, that is not the problem. The thing is that i declared $sCapabilities local to SetupChrome, i just add Return $sCapabilities in _SetupChrome then it works. Now i improve my scrip. Thank you so much and...

Happy new year!!!

 

Link to comment
Share on other sites

@iSanGlad you got the initial kinks worked out. A few suggestions --

  • As previously mentioned, you should update WinHTTP to avoid some know issues that can occur with v1.6.4.1
  • Add some error checking to your custom functions. For example, if _WD_FindElement returns an error then it makes no sense to continue with call to _WD_ElementAction
Link to comment
Share on other sites

Hi @Danp2,i have code u can see help me if i open  1 file exe run with chromedriver.exe and open 2 file will chromedriver 1 wiil cloe. i set

G lobal $_WD_DRIVER_CLOSE = False ; Close prior driver instances before launching new one
Global $_WD_DRIVER_DETECT = False ; Don't launch new driver instance if one already exists
Global $_WD_RESPONSE_TRIM = -1 ; Trim response string to given value for debug output
Global $_WD_ERROR_MSGBOX = False ; Shows in compiled scripts error messages in msgboxes
 
and set in my code
 
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"')
_WD_Option('DriverClose',False)
 
 
still close chromedriver 1
Link to comment
Share on other sites

@DoVinhTrungThe following two lines of code perform the same action --

_WD_Option('DriverClose',False) 
 
$_WD_DRIVER_CLOSE = False

While you can modify the global variables directly, using _WD_Option to access / modify these variables is the recommended method.

You may want to check the chome.log file to see if it gives the reason for one of the chromedriver instances closing. You haven't provided enough details to know for sure, but it could be because you aren't using a unique port number combination for each set of Chrome / Chromedriver.

I suggest that you review this prior thread.

Link to comment
Share on other sites

Please advise which library to use to work with Xpath.
I am currently using WebDriver UDF to read a table of 100 rows and 12 columns and query each cell <td> via :

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

There are 2 queries per cell. This is slow and inefficient.
I want to take the whole table into memory with the command

$sTable = _WD_ElementAction($sSession, $sElementIdTable, 'property', 'outerHTML')

and extract <tr> and <td> from $sTable.
Is there a library that handles string variables via Xpath?
It would be very convenient to change the code so that it leaves the search keys for Xpath exactly the same as for WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, ....).
Can you please suggest a library with the closest syntax in terms of Xpath?

PS _WD_GetTable cannot be used. as I am retrieving different objects from the same cell. And _WD_GetTable glues all the text into one value and I can't separate it into its components.
Thank you!
 

Link to comment
Share on other sites

Hi @dadLog,

can you share the DOM structure of your table? Then it is probably more easy to recommend a better XPath instead what you are trying to do 🤞 .

7 minutes ago, dadLog said:

[...] _WD_GetTable cannot be used. as I am retrieving different objects from the same cell. And _WD_GetTable glues all the text into one value and I can't separate it into its components [...]

How this will look like? Please show your data, DOM etc., thanks 🤝 .

Best regards
Sven

________________
Stay innovative!

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

22 minutes ago, SOLVE-SMART said:

Please show your data, DOM etc., thanks

<td class="MTC-root MTC-body jss48">
    <div class="MG-root MG-container MG-spacing-xs-1 MG-direction-xs-column">
        <div class="MG-root jss55 MG-container MG-item MG-wrap-xs-nowrap MG-align-items-xs-center MG-justify-xs-space-between">
            <div class="jss56">
                <p class="MTG-root MTG-body2">City-1</p>
                <span class="MTG-root MTG-caption MTG-colorTextSecondary MTG-noWrap">Data-1</span>
            </div>
            <span class="jss49">
                Number-1
                <span class="jss50 jss52">Number-2</span>
                Number-3
                <span class="jss50">Number-4</span>
                <span class="jss51">Number-5</span>
            </span>
            <div class="jss56">
                <p class="MTG-root MTG-body2">City-2</p>
                <span class="MTG-root MTG-caption MTG-colorTextSecondary MTG-noWrap">Data-2</span>
            </div>
        </div>
        <div class="MG-root MG-item">
            <span class="MTG-root MTG-caption MTG-colorTextSecondary">Comment, strings</span>
        </div>
    </div>
</td>

Output: City-1, Data-1, City-2, Data-2, Number -1,2,3,4,5 and "Comment, strings"

Other <td> very simple -

<td>data1</td>

<td>
    data2
    <span>data2</span>
</td>

Thank you, Sven! )

Edited by dadLog
Link to comment
Share on other sites

Thanks @dadLog.

Hmm, you only need the values of the <span> tags inside the <td> tags, am I right?
Is it a public page (URL) or can you share more of the DOM? The whole <table> structure would be nice. Then I could try it on my own.

Best regards
Sven

________________
Stay innovative!

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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