Jump to content

WebDriver UDF - Help & Support (II)


Danp2
 Share

Recommended Posts

@Nine Thank you very much for the reply.....I didn't know how to send ArrowLeft to the calendar, but I tried something similar. Thank you for showing me this.

I just tried a modified version of your code, by trying again to just use ArrowLeft, but I realized that it will not work because when you go back a month it will display the previous month days again. Very frustrating....and you probably tried this yourself, which is why you are using multiple action statements.

I am wondering if it is possible to read the calendar values in a loop so that you arrowleft until shipate equals the read calendar value?

 

 

 

 

 

Link to comment
Share on other sites

I removed my post because it was inaccurate to say it was working.  Now I am looking at using the arrow button to return back to the right month then select the right day.  Something like this may work better :

Local $sTargetDate = "2020/12/20"
Local $sToday = _NowCalcDate()
Local $iDateDiff = _DateDiff("M", StringTrimRight($sTargetDate, 2) & StringRight($sToday, 2), $sToday)
For $i = 1 to $iDateDiff
  $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//a[@id="calprev"]')
  _WD_ElementAction($sSession, $sElement, 'click')
  Sleep(800)
Next
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//a[@href="#' & Int(StringRight($sTargetDate,2)) & '"]', "", True)

untested 

Link to comment
Share on other sites

@Nine Thank you very much -- I made a few changes and it works! 

Local $sTargetDate = "2020/09/02"
   Local $sToday = _NowCalcDate()
   Local $iDateDiff = _DateDiff("M", StringTrimRight($sTargetDate, 2) & StringRight($sToday, 2), $sToday)

    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath,'//*[@id="shipDateInput"]')
   _WD_ElementAction($sSession, $sElement, 'click')
   For $i = 1 to $iDateDiff
     $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//a[@id="calprev"]')
     _WD_ElementAction($sSession, $sElement, 'click')
     Sleep(800)
   Next
   $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//a[@href="#' & Int(StringRight($sTargetDate,2)) & '"]')
   _WD_ElementAction($sSession, $sElement, 'click')

I mentioned this before in a previous post, but for those that really make a difference and go out of their way to help, like @Nine and @Danp2,  please setup a https://www.buymeacoffee.com/ and put it in your signature block. 

Very much appreciated

Link to comment
Share on other sites

@NSearch Be careful now.  It may happen that there is 2 days with the same number in the month because it is showing part of the previous and part of the next months.  This is why I wanted to have an array.  Here my finalized script :

Local $sTargetDate = "2020/12/20"
Local $sToday = _NowCalcDate()
Local $iDateDiff = _DateDiff("M", StringTrimRight($sTargetDate, 2) & StringRight($sToday, 2), $sToday)
For $i = 1 to $iDateDiff
  $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//a[@id="calprev"]')
  _WD_ElementAction($sSession, $sElement, 'click')
  Sleep(800)
Next
Local $aElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//a[@href="#' & Int(StringRight($sTargetDate,2)) & '"]', "", True)
$sElement = (UBound($aElement) = 1 Or Int(StringRight($sTargetDate,2)) <= 15) ? $aElement[0] : $aElement[1]
ConsoleWrite ("Date elem " & $sElement & @CRLF)
_WD_ElementAction($sSession, $sElement, 'click')

Please donate to this site instead of me.  Thanks.

Edited by Nine
Link to comment
Share on other sites

@Danp2 Long time no see. :) (I have not had a lot of questions for many months. I am getting better at programming in Autoit) 

Quick question, is there a function in webdriver that checks the user's current version of chrome? (I want to be able to inform users if their chrome driver is outdated by having Autoit check for them, aka chrome, updated and the driver no longer works)

If there is not, do you know of any way to perform this action using Autoit? 

 

As always, thank you for your input and time. 

Link to comment
Share on other sites

@nooneclose There are a couple of options that may address your need --

  • _WD_UpdateDriver can be used to download the correct version of the webdriver for the desired browser
  • The next release will contain _WD_GetSession, which for now will return the contents of $_WD_SESSION_DETAILS (captured in _WD_CreateSession). This function will eventually be modified to retrieve live session details once the W3C specs support this feature.
Link to comment
Share on other sites

Meanwhile you can use this :

#include <InetConstants.au3>

Local $dData = InetRead("https://www.whatismybrowser.com/guides/the-latest-version/chrome", $INET_FORCERELOAD)
Local $sText = BinaryToString($dData)
Local $sPattern = '(?s)<table class="table table-striped table-hover">.*?Windows[^\d]*([^<]*)'

Local $sLatestVersion = StringRegExp($sText, $sPattern, 1)[0]
ConsoleWrite ("Latest = " & $sLatestVersion & @CRLF)

Local $sCurrentVersion = RegRead("HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon", "version")
ConsoleWrite ("Current = " & $sCurrentVersion & @CRLF)

 

Link to comment
Share on other sites

I'm looking for a way to select multiple rows in a table to be able to download a zip file. When I do this manually, I click the first element and shift+click the last element.

Before I go down a hairy path, is the best way to accomplish this though building an element action?

The following works, but downloads the files individually instead, which takes much longer as Edge has to scan each for viruses

Spoiler
; [Bunch of setup, searching, etc]

_WD_FrameEnter($sSession, $sMainFrame)

; Find the (hidden) download button on the contextmenu
Local $sDownload = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='menuItem4']")

; Get the rows of the file table
Local $asTableRows = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//tbody[@id='tbody']/tr", Default, True)

For $i=0 To UBound($asTableRows) - 1

    ; Right click the row
    _WD_ElementActionEx($sSession, $asTableRows[$i], "rightclick")

    ; Wait for the context menu to be visible
    If Not _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='menuItem4']", Default, Default, True, True) Then Return SetError(1, @error, False)
    
    ; Click download
    _WD_ElementAction($sSession, $sDownload, "click")

Next

 

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Do you have anywhere to look besides w3's website? I was really hoping to find examples somewhere on some actions (that aren't based on Selenium, ugh). The ones in the UDF are helpful, but there aren't any with key pressing.

I'd be more than happy to share my code if/when I get it working :)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

image.png.3757baefbfdfeb681ddb8724413dc592.png

I need to get span class in this my picture for click this check box. Please tell me for correct scripts.

 

I have try to use scripts in this below but it's not working.

$cName= _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[contains(text(),'001 -  BEAUTY')]")
    _WD_ElementAction($sSession, $cName, 'click')

$cNameClick=_WD_WaitElement($sSession,$_WD_LOCATOR_ByXPath,"//*[@class='rtPlus']")
    _WD_ElementAction($sSession, $cNameClick, 'click')

Link to comment
Share on other sites

@jelly By default, _WD_WaitElement doesn't return the found element. You will need to change your code to this --

$cNameClick=_WD_WaitElement($sSession,$_WD_LOCATOR_ByXPath,"//*[@class='rtPlus']", Default, Default, Default, Default, True)

You didn't provide enough information to know if the above is all that's required to make your script function. If you need further help, then please post additional details, such as --

  • website involved
  • Results from Scite output panel
  • Etc

Regards,

Dan

P.S. Welcome to the forum :welcome:

Link to comment
Share on other sites

Coming back to say, shift-clicking is way easier than I expected. It doesn't seem to be possible to submit a single action that does it all (press shift, move the mouse, click, and release shift), but I'm bad with JSON, so it may be incorrectly formatted. This is what I came up with:

Func _WDEx_ElementShiftClick($sSession, $sElement)

    ; Hold shift down
    Local $sAction = '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyDown", "value": "\uE008"}]}]}'
    _WD_Action($sSession, "actions", $sAction)
    If @error Then Return SetError(1, 0, False)

    ; Easy click?
    _WD_ElementAction($sSession, $sElement, "click")
    If @error Then Return SetError(2, 0, False)

    ; Release shift
    $sAction = '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyUp", "value": "\uE008"}]}]}'
    _WD_Action($sSession, "actions", $sAction)
    If @error Then Return SetError(3, 0, False)
    
;~  ; 4 actions together? Not that I can tell...
;~  $sAction = '{"actions":[{"type":"key","id":"keyboard_1","actions":[{"type":"keyDown","value":"\uE008"}]},'
;~  $sAction &= '{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove",'
;~  $sAction &= '"origin":{"ELEMENT":"' & $sElement & '","' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}},'
;~  $sAction &= '{"button":0,"type":"pointerDown"},{"button":0,"type":"pointerUp"}]},{"type":"key","id":"keyboard_1","actions":[{"type":"keyUp","value":"\uE008"}]}]}'
;~  $sAction &= ']}]}'
;~  _WD_Action($sSession, "actions", $sAction)
    
    Return True

EndFunc

 

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

@seadoggie01 I believe this could be done with a single call to _WD_Action. Untested, but I believe it would look something like this --

; Hold shift down
 Local $sAction = '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyDown", "value": "\uE008"}]}],'

; Move mouse to element
$sAction &= '"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"ELEMENT":"'
$sAction &= $sElement & '","' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}},'

; Perform click
$sAction &= '{"button":2,"type":"pointerDown"},{"button":2,"type":"pointerUp"}]}],'

; Release shift
$sAction &= '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyUp", "value": "\uE008"}]}]}'

_WD_Action($sSession, "actions", $sAction)

I may not have the exact formatting, but you should get the gist of it.

Edit: Here's the corrected code, which I have tested --

$sAction = '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyDown", "value": "\uE008"}]},'

; Move mouse to element
$sAction &= '{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"ELEMENT":"'
$sAction &= $sElement & '","' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}},'

; Perform click
$sAction &= '{"button":0,"type":"pointerDown"},{"button":0,"type":"pointerUp"}]},'

; Release shift
$sAction &= '{"type": "key", "id": "keyboard_2", "actions": [{"type": "keyUp", "value": "\uE008"}]}]}'

_WD_Action($sSession, "actions", $sAction)

I'll see if this can be easily added to _WD_ElementActionEx. It would be nice to have a single directive like "modifierClick' that could be used to perform shift|control|alt clicks.

Edited by Danp2
Link to comment
Share on other sites

Want to use IE11 browser + webdriver, see the help reference, requirements:

Quote

IEDriverServer version number and Selenium version number must be consistent....

I have a question:

where to look at the current selenium version?

In other words:

how to choose the matching 'IEDriverServer' version number that matches 'IE11 browser'?

More thanks!

Edited by Letraindusoir
Link to comment
Share on other sites

3 hours ago, Danp2 said:

@Letraindusoir

Since you're asking the question here, then I'm assuming that you want to do this with AutoIt, not Selenium. Therefore, I believe the quote above doesn't apply. Are you having issues with IEDriverServer?

Recently want to use IEDriverServer + IE11 to operate the web page, feel very bad, there are various problems, initially thought that did not find the right IEDriverServer version. Few people use IE11 now, and there are few examples in the forum...

Edited by Letraindusoir
Link to comment
Share on other sites

How to check the version of chromedriver.exe?

The Chrome browser updates very often and chromedriver.exe is not compatible with different versions, so I'm trying to create some auto-update script.

So, before run all the system I'm doing a kind of check list and verifying all the software version. I already getting the version from Chrome, but there is no information embedded in the chromedriver.exe, is there a way to check it? Or another idea about this update script?

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...