I need to automate some stuff behind some hyperlinks from my university's SAP Portal. I figured using Selenium
is the way to go here. But it turns out most of the web elements there are faked
and created from JavaScript
, that is probably why webdriver cannot SEE them.
Here is what I have to click:
<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>
Here is the page source : https://pastebin.com/Dpc36nxL
Screenshot for understanding: https://imgur.com/a/qvxhVFA
I tried to use a workaround, by using ActionChains
to open up developer console, and inject an artificial CLICK on the desired element, but even that failed because when I try to inject JavaScript at the end, the link here changes each time.
document.querySelector("#Link5908e99d")
Something like this:
assert "Feedback Form" in driver.page_source
# open up the developer console
driver.send_keys(keys.Keys.CTRL+keys.Keys.SHIFT+'i')
driver.perform()
time.sleep(3)
action.send_keys(keys.Keys.ENTER)
# inject the JavaScript...
action.send_keys("document.querySelector("#Link5908e99d").click()"+keys.Keys.ENTER)
action.perform()
How do I go forward with this?
The solution was to switch to the iframe which totally went unnoticed and then find the element using its relative XPath from the iframe.