Jump to content

WebDriver UDF - Help & Support (II)


Danp2
 Share

Recommended Posts

13 minutes ago, CYCho said:

I don't know how to do this. Please let me know how.

The same way that you would copy text from any console window such as cmd.exe. Use google if you still need help.

You could also change this line in the function SetupEdge  --

_WD_Option('DriverParams', '--verbose')

to the following so that the contents are automatically written to a log file --

_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\msedge.log"')

 

Link to comment
Share on other sites

I looked at the msedgedriver console and found this:
 

[SEVERE]: bind() returned an error: 각 소켓 주소(프로토콜/네트워크 주소/포트)는 하나만 사용할 수 있습니다
My translation: only one usage of each socket address (protocol/network address/port) is permitted

This reminded me of the fact that chromedriver and msedgedriver use same port (9515), so I killed the existing chromedriver process and the problem was solved. It seems that they cannot coexist. Thanks for your help.

Link to comment
Share on other sites

Hi everyone , i need some help with this : 

When i have a list of objects like the images and i click one of them but is not visible nothing happens , but if i scroll down and click the object , now visible , it works . 

If there a way to do this without scrolling down ? 

 

image.png

Link to comment
Share on other sites

1 hour ago, Danp2 said:

@ADream It's difficult to assist you when you have provided such a brief description and zero lines of code. I would suggest writing a short example script that we can run to observe the issue you are encountering. Use a different website if you are not able to share the "real" one.

Sorry for the poor descrption :(
let say i have a list of elements like this:

Default view:

f49a9cb04cbd693327647a8a17b937ab.png

If i scroll down a little

3f7aec0f9f0dfe7a6cb9db49488ea71b.png

 

This list have 29 options , if you click one, the profile of the page change .

$oElement1 = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//*[@id='linkSwitchProfile']/ul/li[1]")
$oElement2 = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//*[@id='linkSwitchProfile']/ul/li[16]")

Element 1 represent the first one ( independencia HUARAZ ANCASH) , as you can see this one is visible without scrolling down.
Element 2 represent the 16th ( Chaccho ANTONIO RAIMONDI ANCASH) , i have to scroll down to be able to see this one.  

So my problem is

if im in the default view and i want to click the first one with _WD_ElementAction($sSession,$oElement1,"click") it worked.
but if im in the default view without scrolling down and i wanto to click the 16th with _WD_ElementAction($sSession,$oElement2,"click") nothing happened, i think its because its not visible.
So if i click the element after scrolling down like :

Send({DOWN}) 
_WD_ElementAction($sSession,$oElement2,"click") , it worked.

Is there a way to click succesfully the 16th element without scrolling down ?  

Edited by ADream
Link to comment
Share on other sites

@ADream According to the W3C webdriver specs, the element should automatically be scrolled into view before performing the click. I assume that you are using Chrome. You may want to try with Firefox or Edge to see if the behavior is different there.

Honestly, it still isn't clear to me what type of element you are delaing with. It looks like a dropdown list, but you haven't mentioned a dropdown. Can you show a more complete example of the HTML involved?

Link to comment
Share on other sites

@ADream This works for me --

#include <wd_core.au3>

Local $sDesiredCapabilities

SetupChrome()
_WD_Startup()

Local $sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://www.w3.org/TR/wai-aria-practices-1.1/examples/listbox/listbox-scrollable.html")

Local $oElement1 = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//ul[@id='ss_elem_list']/li[1]")
Local $oElement2 = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//ul[@id='ss_elem_list']/li[16]")

For $x = 1 to 3
    _WD_ElementAction($sSession,$oElement1,"click")
    Sleep(2000)
    _WD_ElementAction($sSession,$oElement2,"click")
    Sleep(2000)
Next

_WD_DeleteSession($sSession)

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

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}'
EndFunc

Post a complete example if you want me to look further into this for you.

Link to comment
Share on other sites

4 hours ago, Danp2 said:

@ADream According to the W3C webdriver specs, the element should automatically be scrolled into view before performing the click. I assume that you are using Chrome. You may want to try with Firefox or Edge to see if the behavior is different there.

Honestly, it still isn't clear to me what type of element you are delaing with. It looks like a dropdown list, but you haven't mentioned a dropdown. Can you show a more complete example of the HTML involved?

Yes i forgot to attach it to my reply , sorry 
7fb1556ff21a3fc718663727da2ea40d.png
So let say the first 5 li elements are visible , and i wan to click on the last one , as you say , when i click on it , it scroll down automatically , but the click failed , because if the mouse is out of the area of this list, the list dissapeared so the click fail because this portion on html only exists if the list is visible . 
 

 

2 hours ago, Danp2 said:

@ADream This works for me --

#include <wd_core.au3>

Local $sDesiredCapabilities

SetupChrome()
_WD_Startup()

Local $sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://www.w3.org/TR/wai-aria-practices-1.1/examples/listbox/listbox-scrollable.html")

Local $oElement1 = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//ul[@id='ss_elem_list']/li[1]")
Local $oElement2 = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//ul[@id='ss_elem_list']/li[16]")

For $x = 1 to 3
    _WD_ElementAction($sSession,$oElement1,"click")
    Sleep(2000)
    _WD_ElementAction($sSession,$oElement2,"click")
    Sleep(2000)
Next

_WD_DeleteSession($sSession)

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

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}'
EndFunc

Post a complete example if you want me to look further into this for you.


It worked in this case because this list have a scroll bar , in my case i dont have a scroll bar in the list, the list show all the options at once so when i say that i have to scroll down i mean scroll bar of the webpage , sorry for my bad description :(
 

 

Edited by ADream
Link to comment
Share on other sites

15 minutes ago, ADream said:

So let say the first 5 li elements are visible , and i wan to click on the last one , as you say , when i click on it , it scroll down automatically , but the click failed , because if the mouse is out of the area of this list, the list dissapeared so the click fail because this portion on html only exists if the list is visible .

It worked in this case because this list have a scroll bar , in my case i dont have a scroll bar in the list, the list show all the options at once so when i say that i have to scroll down i mean scroll bar of the webpage , sorry for my bad description :(

Sorry, but I'm done guessing at this issue so either produce a website that meets your criteria (either the original or a suitable replacement) or else I can't help you.

Link to comment
Share on other sites

30 minutes ago, Danp2 said:

Sorry, but I'm done guessing at this issue so either produce a website that meets your criteria (either the original or a suitable replacement) or else I can't help you.

Thank for your time  , im thinking another aproach , is there a way to set the default zoom through DesiredCapabilities , for example :

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {... ,"zoom": 0.50 ,    ...}}}}'

Link to comment
Share on other sites

3 hours ago, Danp2 said:

@ADream No idea on the zoom question. You'll need to research yourself. Have you tried something like this before performing the click?

_WD_ExecuteScript($sSession, "arguments[0].scrollIntoView(false);", '{"' & $_WD_ELEMENT_ID & '":"' & $oElement2 & '"}')

 

I will try doing that before clicking , thank you so much for your time Danp2
 

I found out that i could set the zoom with this lineswitch :  

--force-device-scale-factor=0.50
https://peter.sh/experiments/chromium-command-line-switches/

Now i have doubts where to place it in DesiredCapabilites.

I was thinking another way to do the zoom out before click an element : 

#Include <Chrome.au3>
#Include "wd_core.au3"
#Include "wd_helper.au3"

Global $sDesiredCapabilities, $sSession

$sSession = CreateSession()

_WD_Navigate($sSession,"https://www.futbin.com/")

For $i = 0 to 3
    Send("^-")
Next

Sleep(2000)
$oElement1 = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"/html/body/header/nav/div/div/ul[1]/li[4]/a")

_WD_ElementAction($sSession,$oElement1,"click")

Func CreateSession()

    SetupChrome()
    _WD_Startup()
    Return  _WD_CreateSession($sDesiredCapabilities)

EndFunc

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, "args":[' & """start-maximized""," & " ""disable-infobars""" & "" & '] ,"prefs": {"plugins.always_open_pdf_externally": true, "download":{"prompt_for_download":true}}}}}}'
EndFunc   ;==>SetupChrome


But i have a problem here:


If you comment this portion :  

For $i = 0 to 3
    Send("^-")
Next

The program works ( click the icon with the red square) 
image.png.7f984ef5141d4aa3974a5637b96b0e5f.png

But if not , the program click other option .
How can i avoid this ? 

Edited by ADream
Link to comment
Share on other sites

  • Moderators

ADream,

And you are in violation of our Forum rules as well. No more posts from you on this subject please or sanctions will follow.

M23

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

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

hi, as I'm new to coding and scripting especially to autoit, I'm very new to this UDF too.

I'm currently working on a web automation, and I want my code to click on a button, as it appears on the webpage, as a confirmation dialog.

Here is the button on the web page's source

<div id="j_idt249" class="ui-confirm-dialog ui-dialog ui-widget ui-widget-content ui-corner-all ui-shadow ui-hidden-container ui-dialog-rtl" role="dialog" aria-labelledby="j_idt249_title" aria-hidden="false" style="width: auto; height: auto; left: 828px; top: 173px; z-index: 1008; display: block;" aria-live="polite"><div class="ui-dialog-titlebar ui-widget-header ui-helper-clearfix ui-corner-top ui-draggable-handle"><span id="j_idt249_title" class="ui-dialog-title">هشدار ثبت اطلاعات</span><a href="#" class="ui-dialog-titlebar-icon ui-dialog-titlebar-close ui-corner-all" aria-label="Close" role="button"><span class="ui-icon ui-icon-closethick"></span></a></div><div class="ui-dialog-content ui-widget-content" style="height: auto;"><span class="ui-icon ui-confirm-dialog-severity ui-icon-alert"></span><span class="ui-confirm-dialog-message">آيا از ثبت اطلاعات اطمينان داريد؟</span></div><div class="ui-dialog-buttonpane ui-dialog-footer ui-widget-content ui-helper-clearfix"><button id="j_idt250" name="j_idt250" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left ui-confirmdialog-yes" type="button" role="button" aria-disabled="false"><span class="ui-button-icon-left ui-icon ui-c ui-icon-check"></span><span class="ui-button-text ui-c">ثبت اطلاعات</span></button><button id="j_idt251" name="j_idt251" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left ui-confirmdialog-no" type="button" role="button" aria-disabled="false"><span class="ui-button-icon-left ui-icon ui-c ui-icon-close"></span><span class="ui-button-text ui-c">انصراف</span></button></div></div>

I used a Do ... Until loop, to search for the text with this code (as a wait for load step):

Do
    $Check_Confirmation_Element = _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='j_idt249_title']")
    $Check_Confirmation_Text = _WD_ElementAction($sSession, $Check_Confirmation_Element, 'text')
Until StringInStr($Check_Confirmation_Text) = "هشدار ثبت اطلاعات"

I guess the dialog's text is not readable by the action.

And, BTW, when after for example sleep(2000) I try to click on the button with this code :

$Confirm_Button = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='j_idt250']")
_WD_ElementAction($sSession, $Confirm_Button, 'click')

Or :

$Confirm_Button = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left ui-confirmdialog-yes']")
_WD_ElementAction($sSession, $Confirm_Button, 'click')

I get nothing.

Can you please help me understand what am I doing wrong ?

Edited by Siwa
Link to comment
Share on other sites

@Siwa A few things I notice --

  • By default, _WD_WaitElement doesn't return an element. You will have to pass the True for optional $lReturnElement parameter if you want it to return an element instead of 0/1.
  • You should get in the habit of checking @error following each call to the webdriver UDF.

Not sure why you need the Do...Until loop. You should be able to do everything with a single call to _WD_WaitElement. Once you have the element, you could then loop if really needed.

Not sure why none of your attempts have worked. It would likely help if you posted the results from the Scite output panel so that we can understand what's happening.

 

Link to comment
Share on other sites

I did the @ error and it was giving me error error 8 and 404, I searched it, and found this was a problem with not finding the element. ( strange )

I was able to it with _IE commands, combined with JS like so :

Do
        $Confirm_Input = $oIE.document.getElementById('j_idt249_title').innertext
        Until StringInStr($Confirm_Input, "هشدار ثبت اطلاعات") <> 0

How can I using in webdriver ?

Edit : I did use the _WD_ExecuteScript with this script which worked on the console but not in the autoit :

 alert(document.getElementById("j_idt249_title").innerText)

is there anyway I can get it not as an alert, and as an object ?

I did use _WD_ExecuteScript with this too, with a response in console and no response in autoit,

j_idt249_title.innerText

And if I run :

$Check_Confirmation_Element = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='j_idt249']")

I get a string with some words and numbers, so I guess it returns it the correct way, but why I can not return it's text ?

Edited by Siwa
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...