Jump to content

WebDriver UDF - Help & Support (II)


Danp2
 Share

Recommended Posts

59 minutes ago, VodkaDiva said:

_WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//span[@class='_4o_3 _3-99']","US Dollars (USD)")   ; Test click "us doolar"  1

Two issues here --

  • This isn't a standard select element, so you can't use this function
  • Even if it was, you aren't calling the function with the correct parameters

You've already figured out how to "pop open" the menu. Now you just need to be able to find the correct element in this popup and then click it.

P.S. Suggest that you change your Facebook password as you've posted it in your script above

Link to comment
Share on other sites

Thanks dan !
I use "_WD_ElementOptionSelect" to test and forget delete :( . and i thing about to click 2 time  .
I have open "pop open" but you can see in image 1 and 2 . not thing chagne when i click select . And i can't right click to select tab to find element :( 
I use addon to check element is : //*[@id="js_bl"]/div[1]/div[1]/ul[1]/li[51]/a[1]/span[1]/span[1]
But it notworking . Cant you check for me code again . 
i waste me 2 day :( . thanks dan again ! 

xxxxxxxxxxx

Link to comment
Share on other sites

Dan you really really really genius! it working. Thanks dan
Hope all good things come to you.
Thanks you again ! 

Just now, Danp2 said:

This works for me --

_WD_LinkClickByText($sSession, "Thai Baht")

Change the text to match your desired currency.

xxxxxxxxxxx

Link to comment
Share on other sites

I found this information about how to connect to existing Chrome instance:

 

https://cosmocode.io/how-to-connect-selenium-to-an-existing-browser-that-was-opened-manually/

https://intellitect.com/selenium-chrome-csharp/

 

Any concept how to do that with this AutoIt UDF ?

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:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

I have a problem when shutdown browser with function _WD_Shutdown no working ( Chromedriver don't close ). I use chromedriver 80. I try other PC but same error.

Code for wd_demo

#include "wd_core.au3"
#include "wd_helper.au3"
Local $sDesiredCapabilities, $sSession
SetupChrome()

_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://www.facebook.com")
_ChromeSetInputValueById($sSession,'email','abc')
_ChromeSetInputValueById($sSession,'pass','xyz')
_WD_Shutdown()

Func SetupChrome()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":[' & """start-maximized""," & " ""disable-infobars""" & "" & '] }}}}'
EndFunc   ;==>SetupChrome
Func _ChromeSetInputValueById($sSession,$Id,$Value)
 $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']")
 _WD_ElementAction($sSession,$sButton,'value', $Value)
EndFunc

Log

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\ngoct\Desktop\New folder\wd_demo.au3"    
_WDStartup: OS: WIN_10 WIN32_NT 18362 
_WDStartup: AutoIt: 3.3.14.5
_WDStartup: WD.au3: 0.1.0.15
_WDStartup: Driver: chromedriver.exe
_WDStartup: Params: --log-path="C:\Users\ngoct\Desktop\New folder\chrome.log"
_WDStartup: Port:   9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars"] }}}}
__WD_Post: StatusCode=200; ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"acceptSslCerts":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedriverVersion":"2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a)","userDataDir":"C:\\Users\\ngoct\\AppData\\Local\\Temp\\scoped_dir11160_16333"},"cssSelectorsEnabled":true,"databaseEnabled":false,"goog:chromeOptions":{"debuggerAddress":"localhost:52928"},"handlesAlerts":true,"hasTouchScreen":false,"javascriptEnabled":true,"locationContextEnabled":true,"mobileEmulationEnabled":false,"nativeEvents":true,"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platform":"Windows NT","rotatable":false,"setWindowRect":true,"takesHeapSnapshot":true,"takesScreenshot":true,"unhandledPromptBehavior":"","version":"80.0.3987.122","webStorageEnabled":true},"sessionId":"f4562a56f017819c4986725f6293074c"}}
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"acceptSslCerts":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedriverVersion":"2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a)","userDataDir":"C:\\Users\\ngoct\\AppData\\Local\\Temp\\scoped_dir11160_16333"},"cssSelectorsEnabled":true,"databaseEnabled":false,"goog:chromeOptions":{"debuggerAddress":"localhost:52928"},"handlesAlerts":true,"hasTouchScreen":false,"javascriptEnabled":true,"locationContextEnabled":true,"mobileEmulationEnabled":false,"nativeEvents":true,"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platform":"Windows NT","rotatable":false,"setWindowRect":true,"takesHeapSnapshot":true,"takesScreenshot":true,"unhandledPromptBehavior":"","version":"80.0.3987.122","webStorageEnabled":true},"sessionId":"f4562a56f017819c4986725f6293074c"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/f4562a56f017819c4986725f6293074c/url; $sData={"url":"https://www.facebook.com"}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_Navigate: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/f4562a56f017819c4986725f6293074c/element; $sData={"using":"xpath","value":"//input[@id='email']"}
__WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"dcbc9b26-aa3d-423c-a046-3e07eba5a3b1"}}
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"dcbc9b26-aa3d-423c-a046-3e07eba5a3b1"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/f4562a56f017819c4986725f6293074c/element/dcbc9b26-aa3d-423c-a046-3e07eba5a3b1/value; $sData={"id":"dcbc9b26-aa3d-423c-a046-3e07eba5a3b1", "text":"abc", "value":["a","b","c"]}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ElementAction: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/f4562a56f017819c4986725f6293074c/element; $sData={"using":"xpath","value":"//input[@id='pass']"}
__WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"00e3a503-4311-4440-92ae-dd3c8ef3f3ac"}}
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"00e3a503-4311-4440-92ae-dd3c8ef3f3ac"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/f4562a56f017819c4986725f6293074c/element/00e3a503-4311-4440-92ae-dd3c8ef3f3ac/value; $sData={"id":"00e3a503-4311-4440-92ae-dd3c8ef3f3ac", "text":"xyz", "value":["x","y","z"]}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ElementAction: {"value":null}
>Exit code: 0    Time: 16.93


How do fix.

Thanks anyone

 

Link to comment
Share on other sites

Dear Dan ! 

I use this code about 1 week . but last night i have use antivirut to fix file in "services"  .and now it notwoking . i don't know how to check :( . can you hlep me ? 
When to sesion 1 it ok => go to session 2 ok => but when comebank session1 it notworking
Thanks dan

#include "wd_core.au3"
#include "wd_helper.au3"
#include <GUIConstantsEx.au3>
#include <CoProc.au3>
Global $sDesiredCapabilities, $iIndex, $sSession,$i=1
Global $nMsg, $lProcess = False
Global $sElementSelector = "//input[@name='q']"
Global $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true }}}}'
Global $sFilePath = @ScriptDir & "\1.txt"

   Setupopen()
   $sSession1 = _WD_CreateSession($sDesiredCapabilities)
  _WD_Navigate($sSession1, "https://dantri.vn")     ; Link trang Info
   Setupopen()
   $sSession2 = _WD_CreateSession($sDesiredCapabilities)
  _WD_Navigate($sSession2, "https://dantri.vn")     ; Link trang Info

   _WD_Navigate($sSession1, "https://zing.vn")          ; Link trang Info
   _WD_Navigate($sSession2, "https://google.vn")        ; Link trang Info

   _WD_Navigate($sSession1, "https://kenh14.vn")        ; Link trang Info
   _WD_Navigate($sSession2, "https://kenh14.vn")        ; Link trang Info

Exit

Func SetupChrome()
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}'
EndFunc
Func Setupopen()
   ; Set debug level
   $_WD_DEBUG = "Full"
   ; Execute browser setup routine for user's browser selection
   Call(SetupChrome)
   _WD_Startup()
   If @error <> $_WD_ERROR_Success Then
       Exit -1
   EndIf
EndFunc

 

Edited by VodkaDiva

xxxxxxxxxxx

Link to comment
Share on other sites

Apologises if this has been covered before.

I would like to write a script which attaches to a Firefox session that was created by another script. i.e. both scripts are attached to the same instance of Firefox.

Is that possible?

Thanks

Kalavo 

Link to comment
Share on other sites

@VodkaDiva There are a few issues with your script --

  • "Full" isn't a valid option for $_WD_DEBUG. Suggest that you leave it at the default of $_WD_DEBUG_Info until you get your script fully debugged
  • _WD_Startup should only be called once. Each time it is called it will close any previously existing webdriver consoles, which explains why you can't get back to session 1

Please provide a detailed explanation for why you are attempting to create multiple sessions and why you can't accomplish the same thing with a single session.

Link to comment
Share on other sites

Just now, Danp2 said:

@VodkaDiva Có một vài vấn đề với tập lệnh của bạn -

  • "Đầy đủ" không phải là một tùy chọn hợp lệ cho $ _WD_DEBUG. Đề nghị bạn để nó ở mặc định là $ _WD_DEBUG_Info cho đến khi bạn gỡ lỗi hoàn toàn cho tập lệnh của mình
  • _WD_Startup chỉ nên được gọi một lần. Mỗi lần nó được gọi, nó sẽ đóng mọi bảng điều khiển webroll trước đó, điều này giải thích tại sao bạn không thể quay lại phiên 1

Vui lòng cung cấp giải thích chi tiết về lý do tại sao bạn cố gắng tạo nhiều phiên và lý do tại sao bạn không thể hoàn thành điều tương tự với một phiên duy nhất.

I have to open 2 chrome to login 2 facebook. And it work when i creaate 2 session to use 2 chrome . but now it not . do you thing i have install anything again ?

xxxxxxxxxxx

Link to comment
Share on other sites

@VodkaDiva Not sure how this code would have previously worked unless something else has changed on your end. You previously stated

Quote

last night i have use antivirut to fix file in "services"

I'm unsure what was done here, so can't say if this is the reason for the failure or not.

Has anything else changed, like updating to a newer version of the Webdriver UDF or upgrading Chrome / Chromedriver?

Link to comment
Share on other sites

@VodkaDiva I tried the following and it allowed me to create two separate instances of Chrome, each with it's own profile, using a single instance of Chromedriver --

#include "wd_core.au3"
Global $sDesiredCapabilities

   Setupopen()
   $sSession1 = _WD_CreateSession($sDesiredCapabilities)
  _WD_Navigate($sSession1, "https://google.com")
   $sSession2 = _WD_CreateSession($sDesiredCapabilities)
  _WD_Navigate($sSession2, "https://google.com")

  _WD_Navigate($sSession1, "https://facebook.com")
  _WD_Navigate($sSession2, "https://facebook.com")

Exit

Func SetupChrome()
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}'
EndFunc

Func Setupopen()
   ; Set debug level
   $_WD_DEBUG = $_WD_DEBUG_Info
   ; Execute browser setup routine for user's browser selection
   Call(SetupChrome)
   _WD_Startup()
   If @error <> $_WD_ERROR_Success Then
       Exit -1
   EndIf
EndFunc

Essentially, you need to drop the 2nd call to the Setupopen routine.

Link to comment
Share on other sites

Just now, Danp2 said:

@VodkaDiva I tried the following and it allowed me to create two separate instances of Chrome, each with it's own profile, using a single instance of Chromedriver --

Essentially, you need to drop the 2nd call to the Setupopen routine.

It working ! hahaha h
Love you dan ! You are the best ! 
Have a nice day dan ! Love you 

xxxxxxxxxxx

Link to comment
Share on other sites

Hi @Danp2,

I'm trying to use your UDF without success, 

Following my environment configuration:

Default location of Chrome: C:\Program Files (x86)\Google\Chrome\Application
Chrome version:  80.0.3987.149 (Official Build) (64-bit)
ChromeDriver: 81.0.4044.69 on port 9515
chrome.log is empty

Windows Firewall is disabled

and when I run wd_demo.au3 I got:

_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.2.0.6
_WDStartup: WinHTTP:    1.6.4.1
_WDStartup: Driver:    chromedriver.exe
_WDStartup: Params:    --log-path="C:\Temp\Programacion\A3\WEB Browser\00-WebDriver UDF\chrome.log"
_WDStartup: Port:    9515
_WD_Startup ==> General Error: Error launching web driver!

ÇThanks in advance for your help.

Link to comment
Share on other sites

@jcpetu There's a newer version of the WinHTTP UDF available on Github. Please grab the updates from here.

Where did you place the chromedriver executable? If it's outside of the current directory, then you'll need to adjust the line to include the full path like this --

_WD_Option('Driver', 'c:\full\path\to\the\executable\chromedriver.exe')

Edit: You are also running the wrong version of Chromedriver. For Chrome 80, you should be running Chromedriver 80.0.3987.106

Edited by Danp2
Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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