Looking to automate tasks involving hyperlinks on my university's SAP Portal, I decided to use Selenium
. However, encountering difficulties as many web elements are dynamically generated using JavaScript
, making them invisible to the webdriver.
The element I need to click on is:
<a class="urLnkDragRelate" id="Link6c5f851b" ct="LN" st="" tabindex="0" ti="0" title="Feedback Form" onkeydown="return (sapUrMapi_Link_activate('Link6c5f851b',event))" href="javascript:void(0)" target="" onclick="return htmlbDoEvent(this,'C','onclick','0','htmlb_222143_0',6,1,'',0);">
<span class="urFontStd">
<span ct="TV" class="urTxtStd">Feedback Form</span>
</span>
</a>
Page source: https://pastebin.com/Dpc36nxL
Screenshot for reference: https://i.stack.imgur.com/x1BM5.jpg
Attempts were made by using ActionChains
to interact with the developer console and simulate a click on the element but faced challenges due to dynamic link changes. For example:
document.querySelector("#Link5908e99d")
Code snippet used:
assert "Feedback Form" in driver.page_source
# Access developer console
driver.send_keys(keys.Keys.CTRL+keys.Keys.SHIFT+'i')
driver.perform()
time.sleep(3)
action.send_keys(keys.Keys.ENTER)
# Inject JavaScript...
action.send_keys("document.querySelector("#Link5908e99d").click()"+keys.Keys.ENTER)
action.perform()
Seeking advice on how to proceed from here?
A solution was found by switching to an iframe which enabled locating the element using its relative XPath within the iframe.