Jump to content

Recommended Posts

Posted (edited)

Really thank to @SOLVE-SMART and @Danp2 are trying to help me. I show more of the DOM, because this web need Login so i can not share.

- I try to SetInputValue in the <input id="ctl00_FastBusiness_MainReport_dirExtender_form_ngay_lct"> contains special characters in datatype: <value="  /  /    "> it's date type, and default <text="04/01/2023"> . Firstly, i do clearring the <input> with _WD_ClearElement but it does not work. Then i use _WD_SetInputValue, my input value : 05052022, default="04/01/2023", it changes to "04/05/0520". I think ElementAction(...,'value') does click on midle of Element then put value. Is there any way to setvalue from left of Element? I don't know my explanation is hard to understand for you guys but i started fell hesitate because asking many times for a problem 😕

<td id="ctl00_FastBusiness_MainReport_dirExtender0_formCell_1.15" nowrap="" style="overflow:hidden;width:100%;padding:4px!important;" colspan="1" class="FormCell Required ctl00_FastBusiness_MainReport_dirExtender">
  <div style="width:100%;overflow:hidden;vertical-align:middle;" class="FormContainer FormContainerInput ">
    <input id="ctl00_FastBusiness_MainReport_dirExtender_form_ngay_lct" onfocus="$df.focus(this);" onblur="$df.blur(this);" onkeypress="$df.keypress(event, this, 'ngay_lct');" style="text-align: left; width: 77px;" ondrop="return false" spellcheck="false" autocomplete="off" class="FormInput FormTextInput" type="text" value="  /  /    " oncontextmenu="$func.showContextMenu(event, this, 'v', false);return false;" text="04/01/2023">
  </div>
</td>

 

  On 1/5/2023 at 2:15 PM, Danp2 said:

Lack of error checking. You should check the result of _WD_WaitElement before blindly continuing to call additional functions.

Expand  

- Tobe honest, i'm not a coder and noob in Autoit, use Autoit to support my office job. I never put a check Error in my other script 😐 Help me a code Check if @Error then stop scrip, not Exit

 

  On 1/5/2023 at 2:15 PM, Danp2 said:

Your code is inefficient because it requires you to call _WD_WaitElement multiple times for the same xpath

Expand  

- I only call _WD_WaitElement twice, not much so i think that is not the concern.

_WD_ClearElement($sSession, "//input[@id='ctl00_FastBusiness_MainReport_dirExtender_form_ngay_lct']") 
   Sleep(300)
_WD_SetInputValue($sSession, "//input[@id='ctl00_FastBusiness_MainReport_dirExtender_form_ngay_lct']", '05052022') 
   Sleep(100)
   
Func _WD_SetInputValue($sSession, $xPath, $Value)
   $Element = _WD_WaitElement($sSession, 'xpath', $xPath, 100, 100)
   _WD_ElementAction($sSession, $Element, 'value', $Value)
EndFunc

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

Func _WD_ClearElement($sSession, $xPath)
   $Element = _WD_WaitElement($sSession, 'xpath', $xPath, 100, 100)
   _WD_ElementAction($sSession, $Element, 'Clear')
EndFunc

 

Edited by iSan
Posted
  On 1/6/2023 at 3:03 AM, iSan said:

Help me a code Check if @Error then stop scrip, not Exit

Expand  

See _WD_LinkClickByText for an example of how to check for error after calling _WD_FindElement. Notice that it only proceeds with calling _WD_ElementAction if no error has occurred.

  Quote

I only call _WD_WaitElement twice, not much so i think that is not the concern.

Expand  

Imagine doing this for lots of elements. It could make your script take twice as long to execute.

  Quote

I show more of the DOM, because this web need Login so i can not share.

Expand  

Unfortunately, this doesn't help in this instance. Can you show us the results from plugging the URL into this link? That may help identify the framework being used. Another option is to use _WD_SetElementValue instead of _WD_ElementAction. Try changing the line --

   _WD_ElementAction($sSession, $Element, 'value', $Value)

to

_WD_SetElementValue($sSession, $Element, $Value, $_WD_OPTION_Advanced)

 

Posted

I am having a problem with one of the servers I am on. I can't seem to figure out the problem.

It is working on 2 other identical servers. However, it will not work on my third. So something is difrent. I am just not sure what. 

;WebDriver Func
#include <wd_core.au3>
#include <wd_helper.au3>
#include <ConnView.au3> ;this is used to check port. useful for multiple connections on the same server.

;Hotkey to stop the scirpt
HotKeySet(("{ESC}"), "Terminate")

;Used for Webdriver Functions
Global $sDesiredCapabilities, $sSession, $_Port, $aHandles
Global $iAltPort = 9515
Global $aTCPArray = _CV_GetExtendedTcpTable()


;Finds a avalible port if running on RDC (Remote Desktop Computer) This is needed if multiple users are running a script on the server at the same time.
;Starts at 9515 and +1 after
SetupChr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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


Func Terminate()
    _WD_DeleteSession($sSession)
    _WD_Shutdown()
    Exit
EndFunc   ;==>Terminate




Func SetupChrome($iAltPort) ;Setup for chrome ports and chrome drive exe

    While 1
        $_Port = _ArrayFindAll($aTCPArray, $iAltPort, 0, 0, 0, 0, 2)
        If @error Then
            ExitLoop
        Else
            $iAltPort = $iAltPort + 1
        EndIf
    WEnd

    _WD_Option('Driver', 'chromedriver.exe') ; the .exe file name needs to be changed for each person
    _WD_Option('DriverParams', '--verbose --port=' & $iAltPort & ' --log-path="' & @ScriptDir & '\chrome.log"')
    _WD_Option('Port', $iAltPort)
    _WD_Option('DriverClose', False)
    _WD_Option('DriverDetect', False)
    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Google\\Chrome\\User Data\\", "--profile-directory=Default"], "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}'


;MsgBox($MB_OK, 'Message', 'Click OK to start Chrome Driver at local port: ' & $iAltPort)
_WD_Startup() 
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_LoadWait($sSession)

;;Which site to navigate to.
_WD_Navigate($sSession, "google.com") 
_WD_LoadWait($sSession)


EndFunc   ;==>SetupChrome

Chrome will not open. I have had this problem in the past, but it always seemed to be because I had the wrong version of chrome driver. However, I know I have the right version. 

Here is my output. 

>"C:\Users\BOTIE05\Desktop\New Verision of AutoIT\New Verision of AutoIT\SciTe\..\AutoIt3.exe" /ErrorStdOut "C:\Users\BOTIE05\Desktop\Chrome Template.au3"    
_WD_Option ==> Success [0] : Parameters:   Option=Driver   Value=chromedriver.exe
_WD_Option ==> Success [0] : Parameters:   Option=DriverParams   Value=--verbose --port=9515 --log-path="C:\Users\BOTIE05\Desktop\chrome.log"
_WD_Option ==> Success [0] : Parameters:   Option=Port   Value=9515
_WD_Option ==> Success [0] : Parameters:   Option=DriverClose   Value=False
_WD_Option ==> Success [0] : Parameters:   Option=DriverDetect   Value=False
_WD_IsLatestRelease ==> General Error [1]
_WD_Startup: OS:    WIN_2019 WIN32_NT 17763 
_WD_Startup: AutoIt:    3.3.16.0
_WD_Startup: Webdriver UDF: 0.10.1 (Update status unknown [1])
_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:    --verbose --port=9515 --log-path="C:\Users\BOTIE05\Desktop\chrome.log"
_WD_Startup: Port:  9517
_WD_Startup: Command:   "chromedriver.exe" --verbose --port=9515 --log-path="C:\Users\BOTIE05\Desktop\chrome.log" 
_WD_Startup ==> Success [0]
__WD_Post ==> Webdriver Exception [10] : HTTP status = 500
_WD_CreateSession ==> Webdriver Exception [10]
_WD_LoadWait ==> Invalid session ID [15] : Parameters:    Delay=Default    Timeout=Default    Element=Default
__WD_Post ==> Invalid session ID [15] : HTTP status = 404
_WD_Navigate ==> Invalid session ID [15] : Parameters:   URL=google.com
_WD_LoadWait ==> Invalid session ID [15] : Parameters:    Delay=Default    Timeout=Default    Element=Default

Not really sure on how to read much of the chrome log. However, I did find this at the bottom.

[1673039187.542][INFO]: [ec9653b0e61c705758686b9f1074c830] RESPONSE InitSession ERROR unknown error: cannot create temp dir for unpacking extensions
[1673039187.542][DEBUG]: Log type 'driver' lost 2 entries on destruction
[1673039187.542][DEBUG]: Log type 'browser' lost 0 entries on destruction

I tried creating a folder inside my temp account and switching my environment variables. It diden't work though. 

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Posted (edited)

Hi @SkysLastChance,

hmm, an 500 Internal Server Error is quite annoying, I know.

Is your Webdriver log level (debug) set to full?

$_WD_DEBUG = $_WD_DEBUG_Full

Maybe you can get more information from the Webdriver, but I guess not 😔 .

Please ensure that your Chrome is really the expected and correct one. I saw you wrote it, but when you call _WD_UpdateDriver() with the $bForce parameter, does it change in any aspect?

Did you tried it with firefox? In case you get the same result, it's more clear it's not the fault of Webdriver as you already assumed too, by your "temp dir" actions.

Besides that I would check the event log or similar to get a glue about a possible different setting of the three server. Best of luck 🤞 .

Best regards
Sven

Edited by SOLVE-SMART

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server, 🔗 Cheat Sheet

  Reveal hidden contents
Posted

Please also double check:

  Quote

[...] "args":["user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Google\\Chrome\\User Data\\" [...]

Expand  

Best regards
Sven

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server, 🔗 Cheat Sheet

  Reveal hidden contents
Posted
  On 1/6/2023 at 9:16 PM, SkysLastChance said:

Webdriver UDF: 0.10.1 (Update status unknown [1])

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

Expand  

You should update both of these.

  Quote

cannot create temp dir for unpacking extensions

Expand  

Enter the following from the Windows' command prompt --

echo %temp%

Make sure that it points to a directory that exists.

Posted

 

echo %temp% showed my problem it had a "2" folder it was trying to post into. I created the folder in the directory and Bingo. 

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Posted (edited)
  On 1/6/2023 at 9:16 PM, SkysLastChance said:

;Finds a avalible port if running on RDC (Remote Desktop Computer) This is needed if multiple users are running a script on the server at the same time. ;Starts at 9515 and +1 after

Expand  

FYI, I wrote a function to handle this when I was previously working on the webdriver BiDi implementation. I just submitted this PR, which adds _WD_GetFreePort to wd_helper. Feel free to test and provide feedback. Also, do you think it would be good to have it default to a predefined range if the min/max values aren't supplied?

Edit: This has been merged into the main branch and will be included in the next release.

Edited by Danp2
Posted (edited)

I try to get how many line/row in a table. Firstly, i use _WD_GetTable.

My code:

$aTable = _WD_GetTable($sSession, '//table[@id="ctl00_FastBusiness_MainReport_dirExtender_FormGridd98_formExtenderPKOrderForm_FormGridd101_gridTable"]')
   _ArrayDisplay($aTable)

My element:

<table id="ctl00_FastBusiness_MainReport_dirExtender_FormGridd98_gridTable" class="GridTable" cellpadding="0" cellspacing="0">

From Consol:

__WD_Post ==> No match [8] : HTTP status = 404
_WD_FindElement ==> No match [8] : Parameters:   Strategy=xpath   Selector=//table[@id="ctl00_FastBusiness_MainReport_dirExtender_FormGridd98_formExtenderPKOrderForm_FormGridd101_gridTable"]   StartNodeID=Default   Multiple=Default   ShadowRoot=Default
_WD_GetTable ==> No match [8]

The question is: 

; Parameters ....: $sSession     - Session ID from _WD_CreateSession
;                  $sBaseElement - XPath of the table to return

is $sBaseElement = '//table[@id="ctl00_FastBusiness_MainReport_dirExtender_FormGridd98_formExtenderPKOrderForm_FormGridd101_gridTable"] '

i'm i right?

Edited by iSan
Posted
  On 1/8/2023 at 1:43 PM, Danp2 said:

Of course, it could be a more complex issue such as frames.

Expand  

 

  On 1/8/2023 at 1:48 PM, iSan said:

So, any other way to get how many line/row in a table?

Expand  

start with: _WD_FrameList()

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)

Yea, i think for this web, we can't locate Table.

I have Element of first Line in this table:

<tr id="ctl00_FastBusiness_MainReport_dirExtender_FormGridd98_gridRow1" class="RowCellDefault" onmouseover="Sys.UI.DomElement.addCssClass(this, &quot;Highlight&quot;);$find(&quot;ctl00_FastBusiness_MainReport_dirExtender_FormGridd98&quot;)._highlightItem(this, 0);" onmouseout="Sys.UI.DomElement.removeCssClass(this, &quot;Highlight&quot;);$find(&quot;ctl00_FastBusiness_MainReport_dirExtender_FormGridd98&quot;)._highlightItem(this, 1);">...</tr>

You can see the first id="ctl00_FastBusiness_MainReport_dirExtender_FormGridd98_gridRow1" 

So, id of lines in this table are numbered in sequence, any way to solve it?

  Quote

start with: _WD_FrameList()

Expand  

@mLipok i will take a look at this.

Edited by iSan
Posted (edited)

Hi @iSan,

I thought we already discussed this and solve it too, regarding counting table row elements 🧐 ?!
Please see this post.

Again:

Global Const $sSelector = '//table[@id="ctl00_FastBusiness_MainReport_dirExtender_FormGridd98_gridTable"]//tr'

MsgBox('', 'Count of found elements', _GetElementsCount($sSelector))

Func _FindElements($sSelector)
    Return _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sSelector, Default, True)
EndFunc

Func _GetElementsCount($sSelector)
    Return UBound(_FindElements($sSelector))
EndFunc

This should work if your posted table element ID is correct.

Best regards
Sven

Edited by SOLVE-SMART

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server, 🔗 Cheat Sheet

  Reveal hidden contents
Posted
  On 1/8/2023 at 1:36 PM, iSan said:

My code:

$aTable = _WD_GetTable($sSession, '//table[@id="ctl00_FastBusiness_MainReport_dirExtender_FormGridd98_formExtenderPKOrderForm_FormGridd101_gridTable"]')
   _ArrayDisplay($aTable)

My element:

<table id="ctl00_FastBusiness_MainReport_dirExtender_FormGridd98_gridTable" class="GridTable" cellpadding="0" cellspacing="0">
Expand  

Looking at this again, the element ID you used in the xpath in _WD_GetTable is different from the element ID shown for the table above. This would explain why it wasn't found. 🙄

Posted (edited)

Hi @Danp2,

yes, exactly 👍 . That's why I provided the "correct" ID in my post above. But still, it's pure guessing until @iSan try to help us with proper information and following some recommendation of how to post your problem 🤨 .

Best regards
Sven

Edited by SOLVE-SMART

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server, 🔗 Cheat Sheet

  Reveal hidden contents
Posted (edited)
  On 1/8/2023 at 2:53 PM, Danp2 said:

Looking at this again, the element ID you used in the xpath in _WD_GetTable is different from the element ID shown for the table above. This would explain why it wasn't found. 🙄

Expand  

@Danp2 My bad. I tryed some other ID,that was the last ID i changed, i did that many times until i get stuck, then i put that ID  in my question without checking.

@SOLVE-SMARTGreatful that FindElement with that id success, but only return 1 value.

'//table[@id="ctl00_FastBusiness_MainReport_dirExtender_FormGridd98_gridTable"]//tr'

And i saw in Func _WD_GetTable of wd_helper.au3 that the id of extended xpath lack a before tbody and tr right?

$aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sBaseElement & "/tbody/tr", "", True) 
; Retrieve the number of table rows

 

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

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