Jump to content

Recommended Posts

  • 3 weeks later...
Posted

@TheOne23 Yes, because a table and it's contents are elements on a webpage just like input, div, etc.  Currently, there isn't a function in the UDF that will retrieve the table and it's contents and return them in an array or whatever.

There has been some work by others in this area. You should be able to locate it by searching this thread or the one in GH&S for the terms "table" or "tbody".

Posted (edited)

 

10 hours ago, TheOne23 said:

Hi Danp2,

Does your UDF able to get tables and contents of a table in a chrome web page?

 

Thank you.

this example may interest you : https://www.autoitscript.com/forum/topic/192730-webdriver-udf-help-support/?do=findComment&comment=1428604

 

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted

Hi Chimp,

Thank you for your inputs.

I have actually the below codes that is working on IE but I have this issue with IE browser with this webpage as it is loading too long and the script will only finish once the browser is done loading.

I am actually looking on a similar way but now using Chrome.

 

local $oIE_call = _IECreate("https://apps.mypurecloud.ie/directory/#/analytics/agents/performance",1)
_IELoadWait($oIE_call)
Local $oInputs = _IETagNameGetCollection($oIE_call, "div")
local $sTxt

sleep(1000)
   Do
      For $oInput In $oInputs
         If $oInput.classname = "main-data-table l-scroll-table-stretch data-table l-scroll-table column-picker-toggle ember-view" Then
            $sTxt = $oInput.id      
         EndIf
      Next
         local $container_x = $sTxt
         $oForms1 = _IEGetObjByid($oIE_call, $container_x);"container") ;tabs-master-report
         $oForms2 = _IEPropertyGet($oForms1, "innertext")
   Until $oForms1 <> 0

sleep(1000)

local $sOutput = StringRegExpReplace($oForms2, " \r\n", "")
local $fOutput = StringRegExpReplace($sOutput, "(\v)+", @CRLF)
local $fOutput_1 = StringRegExpReplace($fOutput, "\s", " ")
local $fOutput_2 = StringRegExpReplace($fOutput_1, "(\s{9})", @CRLF)
local $fOutput_3 = StringRegExpReplace($fOutput_2, "((\d{1,})h )?((\d{1,})m )?(\d{1,})s", "$2:$4:$5")
local $fOutput_4 = StringRegExpReplace($fOutput_3, "::","0:0:")
local $fOutput_5 = StringRegExpReplace($fOutput_4, "\s:","0:")
local $file = FileOpen(@scriptdir & "\agents.txt",10)
filewrite($file, $fOutput_5)
Fileclose($file)

 

  • 2 weeks later...
Posted (edited)

Hi!

I'm trying to create a script to my work so it would be easier to fill client's data. To do it, i'm using Webdriver. The problem is, when i try to click in a button, to open client's page, if i need to scroll down to show the button, i can't make it to click the button, but if i pause the script, and manually scroll down till i can see the button and then resume the script that way the button is clicked. From what i searched, the problem is with the boarder of the button, and i found this:

WebElement element = driver.findElement(By.xxx("xxxx"));

String scrollElementIntoMiddle = "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);"
                                            + "var elementTop = arguments[0].getBoundingClientRect().top;"
                                            + "window.scrollBy(0, elementTop-(viewPortHeight/2));";

((JavascriptExecutor) driver).executeScript(scrollElementIntoMiddle, element);

How can i run this in autoit?

Edit: The page have a bar in the bottom, so when the webdriver tries to scroll into the element, it is under the bar, so it can't see and can't click. Whit the option to scroll into the middle of the element (button) it will be visible, i think.

Second question, seems like:

_WD_ElementAction($sSession, $sElement, 'click')

Click in the bottom of the element, for example if i put the page in 90% zoom, it doesn't click in the button of the first client, but in the button of the next client. How can i click in the centre of the element instead of in the bottom?

BTW: I can put here the website since it can only be accessed here and have clients' private information.

Thanks!

Edited by pubeoutros
Posted
38 minutes ago, pubeoutros said:

How can i run this in autoit?

You can use _WD_ExecuteScript to execute this Javascript. Look at the DemoShadowDOM function in wd_demo.au3 for an example of passing an element as a parameter.

You may also want to look into using ScrollIntoViewOptions as a way to modify the scrolling behavior. I haven't done this with Webdriver, but here's a good starting point for you to research further -- https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView

40 minutes ago, pubeoutros said:

Second question, seems like:

_WD_ElementAction($sSession, $sElement, 'click')

Click in the bottom of the element, for example if i put the page in 90% zoom, it doesn't click in the button of the first client, but in the button of the next client. How can i click in the centre of the element instead of in the bottom? 

This function doesn't actually perform the click. It simply passes the request on to the designated webdriver app (chromedriver, getckdriver, etc), which is then responsible for performing the actual request.

Per the W3C specs, I believe the click is supposed to occur at the element's in-view center point. If you are experiencing different behavior, I would recommend testing with a different browser to see if the issue is generic or browser-specific.

As far as the "90% zoom" stuff, this isn't something that I've looking into thus far.

Posted

Hi @Danp2

 

I fear using this UDF just because I used the webdriver for a python script I created a few months ago. I had to keep updating the webdriver each time my coworkers updated their browser and I couldn't prevent them from updating it.   Has anything changed or have I missed something as far as using a Chrome Webdriver. Is there a way to create a autoit script that I don't have to keep updating the webdriver each time Chrome updates. Even if I just need a basic subset of features?

 

Thanks

Posted (edited)

First, thanks for your reply!

Now:

9 hours ago, Danp2 said:

You can use _WD_ExecuteScript to execute this Javascript. Look at the DemoShadowDOM function in wd_demo.au3 for an example of passing an element as a parameter.

I can't see where is the DemoShadowDOM function in wd_demo.au3. Can you help me with this?

 

9 hours ago, Danp2 said:

You may also want to look into using ScrollIntoViewOptions as a way to modify the scrolling behavior. I haven't done this with Webdriver, but here's a good starting point for you to research further -- https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView

I will read it, thanks again!

9 hours ago, Danp2 said:

Per the W3C specs, I believe the click is supposed to occur at the element's in-view center point. If you are experiencing different behavior, I would recommend testing with a different browser to see if the issue is generic or browser-specific.

As far as the "90% zoom" stuff, this isn't something that I've looking into thus far.

I tried few times and when the page isn't 100%, the click was always in the button below of the element selected. So i assumed that the click was made in the bottom of the element, so, since the click is made in the center, i can't understand why it sends the click to the button below.

 

New question:

I would like to block user interactions with browser (Chrome in my case), while the script is running, so nobody can use chrome (screw up the job doing by the script) while the script is running. I was thinking in create a square for example in front of the chrome so neither mouseover anything can be done. I thought in change the position of the chrome to a position where mouse can't reach, but i would like to see what the script is doing. What is the best option to do this?

Thanks!

Edited by pubeoutros
Posted
1 hour ago, pubeoutros said:

I can't see where is the DemoShadowDOM function in wd_demo.au3. Can you help me with this?

You are likely running an older version of the UDF. Please update and you will find it.

1 hour ago, pubeoutros said:

would like to block user interactions with browser (Chrome in my case), while the script is running, so nobody can use chrome (screw up the job doing by the script) while the script is running.

Have you considered running in "headless" mode where the browser window isn't visible at all?

Posted (edited)

@Danp2, with your help I have written a code that updates ChromeDriver.exe and WebDriver UDF files. In my Windows 10 computer, I created a task that is scheduled to run every hour about 5 minutes after GoogleUpdate is run. So far it works fine. Please take a look at the UDF part and you may have a say. This will help anyone who uses ChromeDriver regularly.

#include <Inet.au3>
#include <String.au3>
#include "wd_core.au3"

#cs
; commented out as per @Danp2's opinion ( https://www.autoitscript.com/forum/topic/191990-webdriver-udf-w3c-compliant-version-12132019/page/29/?tab=comments#comment-1443580 )
$sGithubSource = _INetGetSource("https://github.com/Danp2/WebDriver/releases/latest")
$aLatestWDVersion = StringRegExp($sGithubSource, '<a href="/Danp2/WebDriver/releases/tag/(.*)">', 1)
$sLatestWDVersion = $aLatestWDVersion[0]

$sCurrentWDVersion = $__WDVERSION ; Const declared in wd_core.au3

If $sLatestWDVersion <> $sCurrentWDVersion Then
    $sZipFile = @ScriptDir & "\WebDriver-" & $sLatestWDVersion & ".zip"
    $iSize = InetGet("https://github.com/Danp2/WebDriver/archive/" & $sLatestWDVersion & ".zip", $sZipFile, $INET_FORCERELOAD, $INET_DOWNLOADWAIT)
    If $iSize > 0 Then
        $sDriverPath = @ScriptDir
        $oShell = ObjCreate ("Shell.Application")
        $FilesInZip = $oShell.NameSpace($sZipFile & "\WebDriver-" & $sLatestWDVersion).items
        $oShell.NameSpace($sDriverPath).CopyHere($FilesInZip, 20) ; 4 - Do not display a progress dialog box, 16 - Click "Yes to All" in any dialog box displayed
        ConsoleWrite("WebDriver was upgraded to version " & $sLatestWDVersion & @CRLF)
    EndIf
Else
    ConsoleWrite("Current WebDriver UDF is the latest version!" & @CRLF)
EndIf
#ce

$sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", "")
If @error Then Exit
$sChromeVersion = FileGetVersion($sPath)
ConsoleWrite("Chrome version - " & $sChromeVersion & @CRLF)

$iPID = Run(@ScriptDir & "\chromedriver.exe --version", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
$sOutput = StdoutRead($iPID)
$aResult = _StringBetween($sOutput, "ChromeDriver ", " (")
$sChromeDriver = @error ? "Not installed" : $aResult[0] ; Ternary operator
ConsoleWrite("Chromedriver version -- " & $sChromeDriver & @CRLF)

$sChromeVersionShort = StringLeft($sChromeVersion, StringInStr($sChromeVersion, ".", 0, -1) - 1)
$sChromeDriverLatest = _INetGetSource("https://chromedriver.storage.googleapis.com/LATEST_RELEASE_" & $sChromeVersionShort)

ConsoleWrite("Chromedriver latest -- " & $sChromeDriverLatest & @CRLF)

If $sChromeDriver = $sChromeDriverLatest Then
    ConsoleWrite("ChromeDriver upgrade not needed!" & @CRLF)
    Exit
EndIf

FileMove(@ScriptDir & "\chromedriver_win32.zip", @ScriptDir & "\chromedriver_win32_old.zip", $FC_OVERWRITE)
$sZipFile = @ScriptDir & "\chromedriver_win32.zip"
$iSize = InetGet("https://chromedriver.storage.googleapis.com/" & $sChromeDriverLatest & "/chromedriver_win32.zip", $sZipFile, $INET_FORCERELOAD, $INET_DOWNLOADWAIT)
;https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_win32.zip

If $iSize > 0 Then
    FileMove(@ScriptDir & "\chromedriver.exe", @ScriptDir & "\chromedriver_old.exe", $FC_OVERWRITE)
    $sDriverPath = @ScriptDir
    $oShell = ObjCreate ("Shell.Application")
    $FilesInZip = $oShell.NameSpace($sZipFile).items
    $oShell.NameSpace($sDriverPath).CopyHere($FilesInZip, 4) ; 4 - Do not display a progress dialog box, 16 - Click "Yes to All" in any dialog box displayed
    ConsoleWrite("Chromedriver was upgraded to version " & $sChromeDriverLatest & @CRLF)
Else
    FileMove(@ScriptDir & "\chromedriver_win32_old.zip", @ScriptDir & "\chromedriver_win32.zip", $FC_OVERWRITE)
    ConsoleWrite("Download of chromedriver zip file failed" & @CRLF)
EndIf

 

Edited by CYCho
Posted (edited)
47 minutes ago, Danp2 said:

Have you considered running in "headless" mode where the browser window isn't visible at all?

Yes, I already considered that, but, after the script runs i need to add more data and check another data and graphics, so i just need to disable chrome while the scrip is running, then i need to have access to chrome without closing it.

 

47 minutes ago, Danp2 said:

You are likely running an older version of the UDF. Please update and you will find it.

I should be blind, I'm using version 0.2.1.0, and in demo, i can't find it, can you help me?

Thanks!

Edit:

Local $Script = _
"WebElement element = driver.findElement(By.id('client_name'));" & _
"String scrollElementIntoMiddle = 'var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);'" & _
"                                            + 'var elementTop = arguments[0].getBoundingClientRect().top;'" & _
"                                            + 'window.scrollBy(0, elementTop-(viewPortHeight/2));';" & _
"((JavascriptExecutor) driver).executeScript(scrollElementIntoMiddle, element);"

_WD_ExecuteScript($sSession, $Script)

I tried this, but i get no scroll into the element. What am i doing wrong?

Edited by pubeoutros
Posted (edited)
26 minutes ago, pubeoutros said:

I should be blind, I'm using version 0.2.1.0, and in demo, i can't find it, can you help me?

Hmmmm... sounds like I haven't updated the demo script on GH. Sorry about that...I'll post the function here in a bit.

Edit: If you look at _WD_GetShadowRoot in wd_helper.au3, you should get the gist of how to correctly pass an element as a parameter to _WD_ExecuteScript

Edited by Danp2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...