Jump to content

WebDriver UDF - Help & Support (II)


Danp2
 Share

Recommended Posts

@CYCho It looks like you've gone one level too deep with shadowroots. Try this modified version --

#include "wd_core.au3"
#include "wd_helper.au3"

_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--log-path=chrome.log')
Local $sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"goog:chromeOptions": {"w3c": true}}}}'

_WD_Startup()
Local $sSession = _WD_CreateSession($sDesiredCapabilities)

Sleep(50)
_WD_ConsoleVisible(False)

_WD_Navigate($sSession, "chrome://settings/help")
Local $oSettingsUISR = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByTagName, "settings-ui")
Local $oTemp = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "#container", $oSettingsUISR)
Local $oSettingsMainSR = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByCSSSelector, "#main", $oTemp)
Local $oSettingsAboutPageSR = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByCSSSelector, "settings-about-page", $oSettingsMainSR)
Local $oChromeStatusDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "#updateStatusMessage", $oSettingsAboutPageSR)

_WD_HighlightElement($sSession, $oChromeStatusDiv, 1)

Here's another alternative for obtaining the same result (replaces code after _WD_Navigate) --

$sJavascript = 'return document.querySelector("body > settings-ui").shadowRoot.querySelector("#main").shadowRoot.querySelector("settings-about-page").shadowRoot.querySelector("#updateStatusMessage")'
Local $STemp = _WD_ExecuteScript($sSession, $sJavascript)
Local $oJson = Json_Decode($STemp)
Local $oChromeStatusDiv  = Json_Get($oJson, "[value][" & $_WD_ELEMENT_ID & "]")
_WD_HighlightElement($sSession, $oChromeStatusDiv, 1)

 

Link to comment
Share on other sites

The function _WD_IsWindowTop($sSession) tells if the window is on top, but I don't find a function to tell any window to be on top. Is there one? I would like the get one of the windows I created on top (I have saved the handle of that window). Can you help?

Link to comment
Share on other sites

Hi I have problem click element 

<input class="RNmpXc" value="I'm can see" aria-label="I'm can see" type="submit" jsaction="sf.lck" data-ved="0ahUKEwjy2M_suMzpAhWYH3AKHVRCB-sQ19QECAw">

When I try with code click Class ="RNmpXc" but don't any action.

_WD_WaitElement($sSession,$_WD_LOCATOR_ByXPath,"//input[@class='RNmpXc']")
$sElement = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//input[@class='RNmpXc']")
_WD_ElementAction($sSession, $sElement, 'click')

I try code JS then working. But I need use WaitElement wait element show.

_WD_ExecuteScript($sSession, "document.getElementsByClassName('RNmpXc')[0].click();")

Thanks 

Link to comment
Share on other sites

You are attempting to click on an element that isn't visible. When you run your your script with $_WD_DEBUG = $_WD_DEBUG_Info, then the Scite console should look like this --

_WD_Post: URL=HTTP://127.0.0.1:9515/session/5f63143161dacee805d6c6472eff70ff/element/856d6abd-2e4a-443f-80de-f965186ccb3c/click; $sData={"id":"856d6abd-2e4a-443f-80de-f965186ccb3c"}
__WD_Post: StatusCode=400; ResponseText={"value":{"error":"element not interactable","message":"element not interactable\n  (Session info: c...
_WD_ElementAction: {"value":{"error":"element not interactable","message":"element not interactable\n  (Session info: c...
_WD_ElementAction ==> Element interaction issue: {"value":{"error":"element not interactable","message":"element not interactable\n  (Session info: chrome=83.0.4103.61)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00719563+2725219]\n\tOrdinal0 [0x00618551+1672529]\n\tOrdinal0 [0x00500202+524802]\n\tOrdinal0 [0x0049A0BA+106682]\n\tOrdinal0 [0x004943B1+82865]\n\tOrdinal0 [0x004AAA9D+174749]\n\tOrdinal0 [0x004941F6+82422]\n\tOrdinal0 [0x004AACE1+175329]\n\tOrdinal0 [0x004B3D7C+212348]\n\tOrdinal0 [0x004AA94B+174411]\n\tOrdinal0 [0x00492528+75048]\n\tOrdinal0 [0x004935A0+79264]\n\tOrdinal0 [0x00493539+79161]\n\tOrdinal0 [0x0062D607+1758727]\n\tGetHandleVerifier [0x00836546+1050150]\n\tGetHandleVerifier [0x00836291+1049457]\n\tGetHandleVerifier [0x008410D7+1094071]\n\tGetHandleVerifier [0x00836B46+1051686]\n\tOrdinal0 [0x00625B06+1727238]\n\tOrdinal0 [0x0062EB7B+1764219]\n\tOrdinal0 [0x0062ECE3+1764579]\n\tOrdinal0 [0x00644C05+1854469]\n\tBaseThreadInitThunk [0x76BC6359+25]\n\tRtlGetAppContainerNamedObjectPath [0x778E7C24+228]\n\tRtlGetAppContainerNamedObjectPath [0x778E7BF4+180]\n"}}

You can adapt your code so that it avoids this scenario --

_WD_WaitElement($sSession,$_WD_LOCATOR_ByXPath,"//input[@class='RNmpXc']", Default, Default, True)

If Not @error Then
    $sElement = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//input[@class='RNmpXc']")
    _WD_ElementAction($sSession, $sElement, 'click')
EndIf

However, I believe that you are targeting the wrong element. Try this instead --

#include "wd_core.au3"
#include "wd_helper.au3"

_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--log-path=chrome.log')
Local $sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"goog:chromeOptions": {"w3c": true}}}}'

_WD_Startup()
Local $sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://google.com")

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//input[@id="gbqfbb"]')
$sAction = '{"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"x":10,"y":10,"type":"pointerMove","origin":{"ELEMENT":"'
$sAction &= $sElement & '","' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}},{"button":0,"type":"pointerDown"},{"button":0,"type":"pointerUp"}]}]}'
_WD_Action($sSession, "actions", $sAction)

$xpath = "//div[@class='gbqfba gbqfba-hvr']"
_WD_WaitElement($sSession,$_WD_LOCATOR_ByXPath, $xpath, Default, Default, True)

If Not @error Then
    $sElement = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath, $xpath)
    _WD_ElementAction($sSession, $sElement, 'click')
EndIf

 

Link to comment
Share on other sites

@Danp2 how would I go about clicking on this href in Edge? 

html:

"<a class="ui-btn ui-btn-icon-right ui-icon-carat-r" href="DashBoard.aspx?Menu=1400000&amp;unique=637261670613291467" data-ajax="false">Requisition / Check Request</a>"

I tried 

$RecApp = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='DashBoard.aspx?Menu=1200000&unique=637260956706661548']")
_WD_ElementAction($sSession, $RecApp, 'click')

but it did not work. got a could not find error. 

Edited by nooneclose
more info
Link to comment
Share on other sites

@Danp2 using _WD_LinkClickByText($sSession, "Match Invoice") worked perfect!!! Thank you very much. The celebration is short lived because I need to click on another link which has nothing unique about it expect the href and the text is the same of the first button. 

how would i do the partial href? 

Link to comment
Share on other sites

@Danp2 I am getting an 

__WD_Post: URL=HTTP:///element; $sData={"using":"xpath","value":"//a[@href='../Receiving/RCVEntry.aspx?unique=637260957947860096']"}
__WD_Post: StatusCode=400; ResponseText={"value":{"error":"invalid selector","message":"The specified selector is invalid.","stacktrace":""}...
_WD_FindElement: {"value":{"error":"invalid selector","message":"The specified selector is invalid.","stacktrace":""}}
_WD_FindElement ==> Webdriver Exception: HTTP status = 400

Error? I tried this:

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@href, '../Receiving/RCVEntry.aspx?unique=']")
_WD_ElementAction($sSession, $sElement, 'click')

I figured out why i was having this problem. I didn't change my old check. I changed it and now it works. :D

here is the working code:

; Click on the Receiving / Match Invoice Button
Do
    Sleep(500)
    _WD_LinkClickByText($sSession, "Match Invoice")
Until _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@href, '/Receiving/RCVEntry.aspx?unique=')]") <> ""

; Click on the Receiving / Match Invoice Link
Do
    Sleep(500)
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@href, '/Receiving/RCVEntry.aspx?unique=')]")
    _WD_ElementAction($sSession, $sElement, 'click')
Until _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//i[@id='erpDefaultRCV_idfRCTNumber_0ZoomImage']") <> ""

 

Edited by nooneclose
solved
Link to comment
Share on other sites

@Danp2 I am sorry, I seem to have a constant need of your help today. How would I go about getting the text from this element?

HTML:

<tr class="cssZoomRowNormal" id="ZoomDisplay0_0" style="cursor: pointer;" 
    onmouseover="$(this).addClass('cssZoomRowSelected');$(this).removeClass('cssZoomRowNormal');" 
    onmouseout="$(this).removeClass('cssZoomRowSelected');$(this).addClass('cssZoomRowNormal');" 
    onclick="if (typeof(event.target.href) != 'undefined')return false;ZoomPickItem('256');;if (typeof(opener.ToolBarPosition) != 'undefined')">
    <td width="1%" style=" BORDER-BOTTOM: lightgrey 1px solid;">&nbsp;</td>
    <td class="cssTxtMed" style=" BORDER-BOTTOM: lightgrey 1px solid;">RCT000300&nbsp;</td>
    <td width="1%" style=" BORDER-BOTTOM: lightgrey 1px solid;" colspan="1">&nbsp;</td>
</tr>

I need the text "RCT000300" from the td element.

When I tried:

$ReceiptNumField = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//td[contains(text, 'RCT0')]")
$ReceiptNum      = _WD_ElementAction($sSession, $TotalReceiptNum, 'text')
ConsoleWrite(@CRLF & @CRLF & "$ReceiptNum = " & $ReceiptNum & @CRLF & @CRLF)

I got nothing. Is there a way to search a nested element? like maybe

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//tr[@id='ZoomDisplay0_0'" & "//td[contains(text, 'RCT0')]")

?

Link to comment
Share on other sites

16 minutes ago, nooneclose said:

Is there a way to search a nested element? like maybe

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//tr[@id='ZoomDisplay0_0'" & "//td[contains(text, 'RCT0')]")

Yes... try something like this --

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//tr[@id='ZoomDisplay0_0']/td[@class='cssTxtMed']")

 

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...