Issue
I am stuck at maneuvering this webpage using JavaScript. The page has a menu 'button', which can be clicked and then a menu rolls down on left side of the page. However, none of the menu items are buttons, they all are some sort of text anchors(internet research). I tried sending clicks to them but nothing really happens. Using console on Google Chrome I was able to find their index but the activation/ click never happens.
I this case I am trying to go in this direction Menu -> Utilities -> Cube -> Inquiry. Clicking Inquiry should open a page in the same window. But doing following I can only go as far as getting the Menu button clicked. Any ideas what I should try here? I am using Power Automate Desktop - un JavaScript function on web page Action.
NOTE: id (ext-gen1234)is dynamic, it sort of changes and is not fixed.
Html:
<div class="x-layer x-menu x-menu-bpcloadmenu" id="ext-gen1100" style="position: absolute; z-index: 15000; visibility: hidden; left: -10000px; top: -10000px; width: auto; max-height: 846px;">
<a class="x-menu-focus" href="#" onclick="return false;" tabindex="-1" id="ext-gen1102"></a>
<ul class="x-menu-list" id="ext-gen1103" style="max-height: 816px;">
<li class="x-menu-list-item " id="ext-gen1173">
<a href="#" class="x-menu-item x-menu-item-arrow" id="ext-gen1174">
<img src="../resources/images/default/s.gif" class="x-menu-item-icon ">
Utilities
</a>
</li>
</ul>
</div>
What I have tried to do in Power Automate Desktop (Run JavaScript function on web page)
function ExecuteScript() {
//Menu button click
document.querySelectorAll('button')[0].click();
//Utilities index activation attempt
document.querySelectorAll('a')[24].click();
//Cube index activation attempt
document.querySelectorAll('a')[80].click();
//Inquiry index activation attempt
document.querySelectorAll('a')[75].click();
}
Only 1st step clicks the Menu button, rest seem to be doing nothing.
Solution
I figured it out with some additional research, turns out the html is responsive to mouse hover to open up menu for next 'step'. First click open the menu button:
function ExecuteScript() {
document.querySelectorAll(\'button\')[0].click();
}
Added all anchors to a list “Current Anchor”, then used For Each loop in the PAD to run the below JavaScript.
function ExecuteScript() {
//determine the xpath of the Anchor using string search method
var xpath = "//a[text()='%CurrentAnchor%']";
var matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
//check if the Anchor is found and look for its id
if (matchingElement) {
// get id of CurrentAnchor (ext-gen1234)
ID = matchingElement.closest('a').id;
//define the element found by ID
var element = document.getElementById(ID);
//set event listener for mouse hover to the element
element.addEventListener('mouseover', function() {
console.log('Event triggered');
});
//send event of mouse hover
var event = new MouseEvent('mouseover', {
'view': window,
'bubbles': true,
'cancelable': true
});
element.dispatchEvent(event);
}
}
Lastly clicking the button to get to the page I wanted to.
function ExecuteScript() {
//determine the xpath of the Anchor using string search method
var xpath = "//a[text()='Inquiries']";
var matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
//check if the Anchor is found and look for its id
if (matchingElement) {
// get id of CurrentAnchor (ext-gen1234)
ID = matchingElement.closest('a').id;
//click the element found by ID
document.getElementById(ID).click();
}
}
Credits: https://stackoverflow.com/a/50206746/17413703 https://stackoverflow.com/a/29289196/18392362
Answered By - rf_dante
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.