Danp2 Posted May 22, 2020 Author Share Posted May 22, 2020 @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) CYCho 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
CYCho Posted May 22, 2020 Share Posted May 22, 2020 @Danp2 Thanks a lot. I'm glad to see that you seem to be OK. Take care. zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
Danp2 Posted May 22, 2020 Author Share Posted May 22, 2020 @frank10 I'm not aware of any way to accomplish this using only Webdriver commands. If you change active tabs via some other method, then you should be able to continue sending commands to the previously active tab via the webdriver. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
frank10 Posted May 22, 2020 Share Posted May 22, 2020 @Danp2 Good point! If I switch the tab with mouse click with autoit, I can send JS commands to the unfocused tab previously "linked" to webdriver. Link to comment Share on other sites More sharing options...
HJL Posted May 22, 2020 Share Posted May 22, 2020 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 More sharing options...
Danp2 Posted May 22, 2020 Author Share Posted May 22, 2020 @HJL I think you have misunderstood the usage of _WD_IsWindowTop. It is designed to be used with frames, so that you can determine if the current browsing context is at the "top level" or is it within a frame. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
HJL Posted May 23, 2020 Share Posted May 23, 2020 (edited) Ok, but is there a function to get an older window on top resp. foreground? Edited May 23, 2020 by HJL Link to comment Share on other sites More sharing options...
Danp2 Posted May 23, 2020 Author Share Posted May 23, 2020 To switch tabs, you would use _WD_Window or _WD_Attach. If your goal is to bring the window to the foreground, then you're back to using standard Autoit commands. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
ngocthang26 Posted May 24, 2020 Share Posted May 24, 2020 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 More sharing options...
Danp2 Posted May 24, 2020 Author Share Posted May 24, 2020 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 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
nooneclose Posted May 27, 2020 Share Posted May 27, 2020 (edited) @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&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 May 27, 2020 by nooneclose more info Link to comment Share on other sites More sharing options...
Danp2 Posted May 27, 2020 Author Share Posted May 27, 2020 First thing to try is using _WD_LinkClickByText, which is a helper function. Coding would look like this -- _WD_LinkClickByText($sSession, "Check Request") Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
nooneclose Posted May 27, 2020 Share Posted May 27, 2020 @Danp2 Thank you I will try that right away. Thank you for your time and input. Link to comment Share on other sites More sharing options...
nooneclose Posted May 27, 2020 Share Posted May 27, 2020 @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 More sharing options...
Danp2 Posted May 27, 2020 Author Share Posted May 27, 2020 Something like -- $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@href, 'DashBoard.aspx?Menu=1200000&unique=']") nooneclose 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
nooneclose Posted May 27, 2020 Share Posted May 27, 2020 (edited) @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. 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 May 27, 2020 by nooneclose solved Link to comment Share on other sites More sharing options...
Danp2 Posted May 27, 2020 Author Share Posted May 27, 2020 @nooneclose Those results don't appear to go along with the code you posted (no "contains" in the xpath from the results). Did you try it like I posted above? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
nooneclose Posted May 27, 2020 Share Posted May 27, 2020 @Danp2 you are correct. I mentioned it in my other post while i was editing it. I forgot to fix my do while. Once I fixed that loop everything was working. I posted the working code in the post before this one. Thank you so much for your help! Link to comment Share on other sites More sharing options...
nooneclose Posted May 27, 2020 Share Posted May 27, 2020 @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;"> </td> <td class="cssTxtMed" style=" BORDER-BOTTOM: lightgrey 1px solid;">RCT000300 </td> <td width="1%" style=" BORDER-BOTTOM: lightgrey 1px solid;" colspan="1"> </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 More sharing options...
Danp2 Posted May 27, 2020 Author Share Posted May 27, 2020 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']") nooneclose 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Recommended Posts