Jump to content

WebDriver UDF (W3C compliant version) - 2024/02/19


Danp2
 Share

Recommended Posts

Hi Danp2, i have resolved the problem by reading the consolelog .. to fix i have set the $options in format json in the function _WD_window (the function doesnt do the translation)

 

all is okay..just long time with the debug .. i have put my complete code in my post if some people have problems.  The objective was to click on a button display inside an iframe.

 

So is there an option to invalidate the debug in console?

Link to comment
Share on other sites

1 hour ago, Frenchy said:

So is there an option to invalidate the debug in console?

Not sure I understand. Do you mean to turn it off? If so, this is controlled by the value of $_WD_DEBUG. You can assign any of these to this variable  to control the log level --

$_WD_DEBUG_None   ; No logging to console
$_WD_DEBUG_Error  ; Error logging to console
$_WD_DEBUG_Info   ; Full logging to console

You can also set $_WD_CONSOLE to a valid filename and the log will be written to a file instead of the console.

Link to comment
Share on other sites

Hi. I'm trying to get the links from a list (on Edge browser). Each list item has the following structure

<li class="activity folder modtype_folder " id="module-8407">
  <div>
    <div class="mod-indent-outer">
      <div class="mod-indent mod-indent-1">
      </div>
        <div>
          <div class="activityinstance">
            <a class="" onclick="" href="https://site.com/mod/folder/view.php?id=8407">
              <img src="https://site.com/theme/image.php/lambda/folder/1602062416/icon" class="iconlarge activityicon" alt=" " role="presentation" />
              <span class="instancename">Some text<span class="accesshide " > Folder</span></span>
            </a>
          </div>
        </div>
    </div>
  </div>
</li>

Full XPath:

/html/body/div[4]/div/div[2]/div/div/section/div/div/ul/li/div[3]/ul/li[42]/div/div/div[2]/div/a

XPath:

//*[@id="module-8407"]/div/div/div[2]/div/a

 

I have tried this in my code

$LINKS = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@class='' and contains(@href,'folder')]", Default, True)

It returns an array with UUID formed values that are clickable items and each one points to the respectively link and so I can use on the them something like _WD_ElementAction($sSession, $LINKS[$i], 'click'), but I haven't a way to get the actual links. So far I can only get the text "Some text".

 

Link to comment
Share on other sites

Hi danp2,

I want to automatically select 1 option in this sequence how, please guide me. I simulate the following:

please help me, i am new to udf web driver.

 

<div class="col-sm-8">
 <select name="PartnerGroup" class="form-control"><option value="">[Chọn nhóm khách hàng]</option>
<option value="1">Phổ thông</option>
<option value="2">Tài chính - Ngân hàng</option>
<option value="3">Ưu tiên (Y Tế, giáo dục)</option>
<option value="4">Thương mại điện tử</option>
<option value="5">Điện lực</option>
<option value="6">Nước</option>
<option value="7">Hành chính công</option>
<option value="8"> KH khu chế xuất, khu Công nghiệp</option>
<option value="9">Mạng Xã Hội</option></select>    </div>

Thank you verry much !!!

ok.png

Link to comment
Share on other sites

@NguyenDuc, First you find the element ID of <select> tag with _WD_FindElement and then change the value of that element with _WD_ElementAction.

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='PartnerGroup']")
_WD_ElementAction($sSession, $sElement, "value", "2") ; if you want to select the 2nd option

 

Link to comment
Share on other sites

42 minutes ago, CYCho said:

@NguyenDuc, First you find the element ID of <select> tag with _WD_FindElement and then change the value of that element with _WD_ElementAction.

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='PartnerGroup']")
_WD_ElementAction($sSession, $sElement, "value", "2") ; if you want to select the 2nd option

 

I don't know why, but it doesn't seem to pick value 2

Link to comment
Share on other sites

9 hours ago, CYCho said:

then change the value of that element with _WD_ElementAction.

I think you meant...

; Name ..........: _WD_ElementOptionSelect
; Description ...: Find and click on an option from a Select element
; Syntax ........: _WD_ElementOptionSelect($sSession, $sStrategy, $sSelector[, $sStartElement = Default])

@NguyenDuc

_WD_ElementOptionSelect($gsSession, $_WD_LOCATOR_ByXPath, "//select[@name='PartnerGroup']/option[@value='1']")

 

Edited by TheXman
Link to comment
Share on other sites

6 minutes ago, TheXman said:

I think you meant...

_WD_ElementOptionSelect

You must be right. Now I remember @Danp2 wrote several functions to deal with option selection. The above code of mine is from my old script which worked and is currently working OK for me. Thanks for pointing out.

Link to comment
Share on other sites

I'm not sure now.  :)  Maybe you could also use

; Name ..........: _WD_SetElementValue
; Description ...: Set value of designated element
; Syntax ........: _WD_SetElementValue($sSession, $sElement, $sValue)

 

Link to comment
Share on other sites

4 minutes ago, TheXman said:

I'm not sure now.  :)  Maybe you could also use

; Name ..........: _WD_SetElementValue
; Description ...: Set value of designated element
; Syntax ........: _WD_SetElementValue($sSession, $sElement, $sValue)

 

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='PartnerGroup']")
_WD_ElementOptionSelect($sSession, $sElement, "value", "2") ;

 

I did this but not correctly, but it doesn't seem to pick value 2

Link to comment
Share on other sites

48 minutes ago, NguyenDuc said:

_WD_ElementOptionSelect($sSession, $sElement, "value", "2") ;

The correct syntax of _WD_ElementOptionSelect is _WD_ElementOptionSelect($sSession, $sStrategy, $sSelector[, $sStartElement = Default]) and this will click on the option box, not select an option item.

The following is the actual Select element I interact with and the code in my first post works well.
 

<select name="ctl00$ContentPlaceHolder1$ddlMobile1" id="ctl00_ContentPlaceHolder1_ddlMobile1">
    <option value="">선택</option>
    <option selected="selected" value="010">010</option>
    <option value="011">011</option>
    <option value="016">016</option>
    <option value="017">017</option>
    <option value="018">018</option>
    <option value="019">019</option>
</select>

You may want to confirm that the correct Select element was identified to begin with.

Link to comment
Share on other sites

5 minutes ago, CYCho said:

The correct syntax of _WD_ElementOptionSelect is _WD_ElementOptionSelect($sSession, $sStrategy, $sSelector[, $sStartElement = Default]) and this will click on the option box, not select an option item.

The following is the actual Select element I interact with and the code in my first post works well.
 

<select name="ctl00$ContentPlaceHolder1$ddlMobile1" id="ctl00_ContentPlaceHolder1_ddlMobile1">
    <option value="">선택</option>
    <option selected="selected" value="010">010</option>
    <option value="011">011</option>
    <option value="016">016</option>
    <option value="017">017</option>
    <option value="018">018</option>
    <option value="019">019</option>
</select>

You may want to confirm that the correct Select element was identified to begin with.

Give me an example okay, bother you !!!!

Link to comment
Share on other sites

  • Moderators

NguyenDuc,

Firstly, when you reply in future, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - responders know what they wrote and it just pads the thread unnecessarily. Thanks in advance for your cooperation.

Secondly, I suggest you change your tone pretty quickly or you will find that you will not have any further responders. Your post above is quite beyond the pale.

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

 

<button class="btn btn-primary" onclick="Brandname.saveAmount(3116)"><i class="fa fa-save"></i> Luu </button>

onclick="Brandname.saveAmount(3116)"

---> 3116 is a random number

$sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@onclick='Brandname.saveAmount(*)']")
    _WD_ElementAction($sSession, $sButton, 'Click')
    _WD_LoadWait($sSession, 200)

I tried like this but it is not correct. Please help me to solve it thanks a lot

 

Link to comment
Share on other sites

  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 2024/02/19
  • 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...