Jump to content

WebDriver UDF (W3C compliant version) - 2024/09/21


Danp2
 Share

Recommended Posts

35 minutes ago, Danp2 said:

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

So the only change i need to make here:

50 minutes ago, pubeoutros said:
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)

 

Is correctly pass an element as a parameter? Except the element, everything looks right?

Link to comment
Share on other sites

8 hours ago, Danp2 said:

@CYCho Thanks... I'll take a look at the code when I get some time.

I am concerned about figuring out if you have uploaded new UDF files on GH, especially the way I capture the current version number from wd_core.au3. And my current code will not detect change of files with the version number remaining unchanged in the GH.

Edited by CYCho
Link to comment
Share on other sites

@CYCho Personally, I think it would be good to add some of this functionality to the UDF, but not everything. For example, auto-updating to the latest UDF version could result in your application failing due to a script breaking change or an unintended bug in the release.

To get the version number of the local copy, why not just #include it and obtain the value from $__WDVERSION?

Link to comment
Share on other sites

@Danp2 have you tested the demo recently packaged in the UDF? I'm noticing a few errors or maybe not errors but due to the reference websites updating.

1) Curious myself if there any reason in DemoNavigation that it takes so long to navigate to the google website after loading chrome? Not a real problem but if I can speed that up on my end, it would be nice.

2) In that same DemoNavigation function, the third thing it does is try to load yahoo into the new tab but it never loads into that tab. I added a 3 second sleep after that yahoo navigation and it does load. What's odd here is that if I just load yahoo in a new tab as so:

_WD_NewTab($sSession,True,10,"https://yahoo.com")

it loads up immediately. I was looking into the _WD_Navigate function and it doesn't have a parameter for 'wait to load page' before continuing

3) I managed to fix the google reference to input name to q rather than q1.  That was easy thanks.

4) Maybe a more difficult question is in  DemoElements after the following button click code

_WD_ElementAction($sSession, $sElement, 'Attribute', 'text')

I am seeing the following error. 

 

_WD_ElementAction ==> No match: {"value":{"error":"stale element reference","message":"stale element reference: element is not attached to the page document\n  (Session info: chrome=79.0.3945.88)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00B3A113+1548563]\n\tOrdinal0 [0x00ABDDA1+1039777]\n\tOrdinal0 [0x00A3E485+517253]\n\tOrdinal0 [0x00A400A5+524453]\n\tOrdinal0 [0x00A3FF94+524180]\n\tOrdinal0 [0x00A40150+524624]\n\tOrdinal0 [0x009D8AF0+101104]\n\tOrdinal0 [0x009D8A53+100947]\n\tOrdinal0 [0x009D6F12+93970]\n\tOrdinal0 [0x009E977D+169853]\n\tOrdinal0 [0x009D31E6+78310]\n\tOrdinal0 [0x009E9991+170385]\n\tOrdinal0 [0x009F2594+206228]\n\tOrdinal0 [0x009E95FB+169467]\n\tOrdinal0 [0x009D160A+71178]\n\tOrdinal0 [0x009D2690+75408]\n\tOrdinal0 [0x009D2629+75305]\n\tOrdinal0 [0x00AD71B7+1143223]\n\tGetHandleVerifier [0x00BD2B46+507814]\n\tGetHandleVerifier [0x00BD2864+507076]\n\tGetHandleVerifier [0x00BD9F47+537511]\n\tGetHandleVerifier [0x00BD3402+510050]\n\tOrdinal0 [0x00ACF29C+1110684]\n\tOrdinal0 [0x00AD938B+1151883]\n\tOrdinal0 [0x00AD94F3+1152243]\n\tOrdinal0 [0x00AD83F5+1147893]\n\tBaseThreadInitThunk [0x75C36359+25]\n\tRtlGetAppContainerNamedObjectPath [0x779D7B74+228]\n\tRtlGetAppContainerNamedObjectPath [0x779D7B44+180]\n"}}

was that because that line was out of order and should have been after $sElement was defined after here:

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sElementSelector)

 

5) Last question maybe easiest. Is there a way to embed chrome browser using this UDF into my own GUI?

Thanks for all your help. Looking good!

Edited by NassauSky
I read it back and didn't sound so nice :-/ Sorry made it nice ;-)
Link to comment
Share on other sites

@NassauSky No, I haven't run the full demo recently, but it shouldn't be too difficult to test.

Quote

Curious myself if there any reason in DemoNavigation that it takes so long to navigate to the google website after loading chrome? Not a real problem but if I can speed that up on my end, it would be nice.

I've noticed this initial delay in Chrome as well, but haven't really investigated because I mostly use Firefox. I believe this delay is coming before the  call to _WD_Navigate, but haven't confirmed this.

Quote

In that same DemoNavigation function, the third thing it does is try to load yahoo into the new tab but it never loads into that tab. I added a 3 second sleep after that yahoo navigation and it does load

Just checked this and it ran fine for me as long as I hadn't run the DemoTimeouts function beforehand. With the delays set in DemoTimeouts, I got the following error --

__WD_Post: URL=HTTP://127.0.0.1:9515/session/104bdb8e4f56fbb7c1aa86a321a6bdb3/url; $sData={"url":"http://yahoo.com"}
__WD_Post: StatusCode; ResponseText={"value":{"error":"timeout","message":"timeout\n  (Session info: chrome=79.0.3945.88)","stacktrace":"Backtrace:\n\tOrdinal0 [0x010FA923+1550627]\n\tOrdinal0 [0x0107A731+1025841]\n\tOrdinal0 [0x00FFC5BE+509374]\n\tOrdinal0 [0x00FFB0E9+504041]\n\tOrdinal0 [0x00FFAD56+503126]\n\tOrdinal0 [0x0100012D+524589]\n\tOrdinal0 [0x01001AAB+531115]\n\tOrdinal0 [0x00FF4458+476248]\n\tOrdinal0 [0x0100002E+524334]\n\tOrdinal0 [0x00FB196E+203118]\n\tOrdinal0 [0x00FA8CDB+167131]\n\tOrdinal0 [0x00F9144A+70730]\n\tOrdinal0 [0x00F924D0+74960]\n\tOrdinal0 [0x00F92469+74857]\n\tOrdinal0 [0x010942F7+1131255]\n\tGetHandleVerifier [0x0119711D+523789]\n\tGetHandleVerifier [0x01196EB0+523168]\n\tGetHandleVerifier [0x0119E207+552695]\n\tGetHandleVerifier [0x0119791A+525834]\n\tOrdinal0 [0x0108B82C+1095724]\n\tOrdinal0 [0x0109636B+1139563]\n\tOrdinal0 [0x010964D3+1139923]\n\tOrdinal0 [0x01095455+1135701]\n\tBaseThreadInitThunk [0x75926359+25]\n\tRtlGetAppContainerNamedObjectPath [0x77937B74+228]\n\tRtlGetAppContainerNamedObjectPath [0x77937B44+180]\n"}}
_WD_Navigate: {"value":{"error":"timeout","message":"timeout\n  (Session info: chrome=79.0.3945.88)","stacktrace":"Backtrace:\n\tOrdinal0 [0x010FA923+1550627]\n\tOrdinal0 [0x0107A731+1025841]\n\tOrdinal0 [0x00FFC5BE+509374]\n\tOrdinal0 [0x00FFB0E9+504041]\n\tOrdinal0 [0x00FFAD56+503126]\n\tOrdinal0 [0x0100012D+524589]\n\tOrdinal0 [0x01001AAB+531115]\n\tOrdinal0 [0x00FF4458+476248]\n\tOrdinal0 [0x0100002E+524334]\n\tOrdinal0 [0x00FB196E+203118]\n\tOrdinal0 [0x00FA8CDB+167131]\n\tOrdinal0 [0x00F9144A+70730]\n\tOrdinal0 [0x00F924D0+74960]\n\tOrdinal0 [0x00F92469+74857]\n\tOrdinal0 [0x010942F7+1131255]\n\tGetHandleVerifier [0x0119711D+523789]\n\tGetHandleVerifier [0x01196EB0+523168]\n\tGetHandleVerifier [0x0119E207+552695]\n\tGetHandleVerifier [0x0119791A+525834]\n\tOrdinal0 [0x0108B82C+1095724]\n\tOrdinal0 [0x0109636B+1139563]\n\tOrdinal0 [0x010964D3+1139923]\n\tOrdinal0 [0x01095455+1135701]\n\tBaseThreadInitThunk [0x75926359+25]\n\tRtlGetAppContainerNamedObjectPath [0x77937B74+228]\n\tRtlGetAppContainerNamedObjectPath [0x77937B44+180]\n"}}
Quote

I am seeing the following error. <snip> was that because that line was out of order and should have been after $sElement was defined after here

Could be... It's also possible that it was supposed to go before the button code. Hard to say when I failed to comment the code. :rolleyes:

Quote

Is there a way to embed chrome browser using this UDF into my own GUI?

Not something I've looked into, but I doubt it.

Link to comment
Share on other sites

Thanks @Danp2

Yes sorry I should of mentioned it was the chrome driver that I'm using.  I was thinking about the DemoTimout function slowing it down but that was set to FALSE and it's skipping the DemoTimeouts function.

The biggest reason I was using chrome is because they have a good M3U8 plugin which and now I see there is a M3U8 plugin for Firefox.  How about an embedded Firefox? Does that even exist? 

Thanks again.

Link to comment
Share on other sites

@NassauSky I've notice the following in the Chromedriver logs --

[1576955595.505][WARNING]: Timed out connecting to Chrome, retrying...

This seems to occur at various time, but seems to explain the several second delay that seems to be occurring. Unsure at this point if there's a fix.

I've modified the DemoTimeouts function so that it saves & restores the timeout settings so running it won't have an affect of subsequent routines. This should be included in the next release.

I'm not knowledgeable on the embedded browser stuff, so unable to provide any feedback or advice on that subject.

Link to comment
Share on other sites

Hi!

I'm trying to learn how to create a script so the "simple" work here in the office gets lighter.

First:

About the javascript code:

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);

I already tried a lot of things, but i can't have it working. I was waiting for the example of DemoShadowDOM function in wd_demo.au3 but you haven't put it yet. So i was trying and trying and trying, but without success.

Btw, if i need to execute another java script, it's always this way?

My last code, like i put in the topic, is:

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)

Second:

Can you have a look at the "90% zoom" stuff? It's possible to change the position of the click in a button from autoit using Webdriver?

Third:

I would like to block user interactions with browser (Chrome in my case), while the script is running, since the script will run after a login and other information added, is there any option to block user to interact with the Chrome, just while the script is running? I was thinking in create a transparent window (that it's from the same size as actual chrome window and moves when chrome moves too, that doesn't block Webdriver to interact with Chrome, but when user try to click or something, it is done in the transparent window. And I "need" to see what the script is doing. Can you help me with this?

Fourth:

I tried to take a screenshot of an element  (a table), but i got nothing, can you please elaborate an example?


I'm sorry for my bad english but isn't my main language and i'm sorry to for being noob, but i'm trying to learn.

Thanks!

Link to comment
Share on other sites

@pubeoutros I believe that I previously suggested that you take a look at the coding of _WD_GetShadowRoot. Your code would look like this if you took the same approach --

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='client_name']")
$sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}'
$Script = "<Your javascript goes here>"
$sResponse = _WD_ExecuteScript($sSession, $Script, $sJsonElement)

You will need to modify the javascript to work within this context, something like this (completely untested) --

$Script = 'var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);' & _
    'var elementTop = arguments[0].getBoundingClientRect().top;' & _
    'window.scrollBy(0, elementTop-(viewPortHeight/2));'

The removed portions are actually being performed in the Autoit code above.

Quote

Can you have a look at the "90% zoom" stuff?

What have you tried to diagnose this yourself? Hint: First thing I would test is if the problem occurs on other browsers.

Quote

I would like to block user interactions with browser. Can you help me with this?

Sorry, but no time to put towards this. Perhaps someone else is willing to assist. Have you tried using the BlockInput function?

Quote

I tried to take a screenshot of an element  (a table), but i got nothing, can you please elaborate an example?

You should post a short reproducer so that we can see what you have attempted thus far.

Link to comment
Share on other sites

Released a new update earlier today and would appreciate it if everyone would test the following new functions and review the coding to make sure that I haven't messed something up 😁 --

  • _WD_IsLatestRelease()
  • _WD_UpdateDriver($sBrowser[, $sInstallDir = Default[, $lFlag64 = Default[, $lForce = Default]]])

Also, there were fixes / enhancements to some of the existing routines related to properly detecting and reporting timeouts. Please let me know if you run into any issues.

Link to comment
Share on other sites

@Danp2 Thanks a lot for the new functions. No you have not messed anythng up. Both of them work as intended. If I may ask for an additional luxury, it would be a different consolewrite when $sDriverLatest = $sDriverVersion and $lForce = False.

Merry Christmas and a Happy New Year!

Edited by CYCho
Link to comment
Share on other sites

2 hours ago, CYCho said:

different consolewrite when $sDriverLatest = $sDriverVersion and $lForce = False

I'm guessing you mean the output "_WD_UpdateDriver ==> Success", correct? That would require setting the value of $iErr to something other than $_WD_ERROR_Success. I'm not sure that any of the existing error codes would suffice, and do we really need to add another error code for this one issue?

P.S. The function returns False if the update wasn't performed. Therefore, you could add your own ConsoleWrite after the call to _WD_UpdateDriver.

Link to comment
Share on other sites

Hi, i tried loading my default User Profile in Chrome or Firefox. 

I tried for Chrome: 

_WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log" --user-data-dir="*PATH TO DIR*"')

and 

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "user-data-dir": "*PATH TO DIR*"}}}}'

 

Anyone get this working? 
I just want to be logged in on some Sites. They have Capchas to log in and im Switching them. So writing a Login Script isnt rally a option. 

Thanks

Link to comment
Share on other sites

I believe that this one has worked for me in past testing --

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Google\\Chrome\\User Data\\", "--profile-directory=Default"]}}}}'

 

Link to comment
Share on other sites

16 minutes ago, Danp2 said:

I believe that this one has worked for me in past testing --

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Google\\Chrome\\User Data\\", "--profile-directory=Default"]}}}}'

 

Thanks you so much, its working. 

Link to comment
Share on other sites

  • 2 weeks later...

Hello all,

 

Thanks in advance for any help on this issue. I am using Selenium Webdriver + geckodriver-v0.26.0-win64 and it looks like the site I am visiting has changed something and now detects that I am using an automated script.

I used to be able to simply navigate (using _WD_Navigate) to the URL below, but now I get redirected to a generic screen (not the intended target).

https://www.fedex.com/servlet/InvoiceServlet?link=4&jsp_name=adjustment&orig_country=US&language=english

 

I have attempted to go upstream, to the page that references the URL above, and click (_WD_ElementAction) the link, but get the same result.

Parent URL: https://www.fedex.com/en-us/customer-support/claims.html 

Link Text: GO TO FEDEX EXPRESS OR FEDEX GROUND

Link References: https://www.fedex.com/servlet/InvoiceServlet?link=4&jsp_name=adjustment&orig_country=US&language=english

 

On the Parent URL link above, there looks to be the following onclick events (not sure if that helps or not):

 

function() {
  if (this.href.indexOf("#") > -1) {
    var b = this.href.substring(this.href.indexOf("#"), this.href.length)
  }
  anchorLink(b)
}
function() {
  var a = $(this).attr("targetid");
  if (a) {
    sessionStorage.setItem("target", a)
  }
}
function onclick(event) {
  FDX.DTM.pushLinkInfo(this)
}

 

Link to comment
Share on other sites

  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 2024/09/21
  • Melba23 pinned this topic

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
 Share

×
×
  • Create New...