Python's Selenium Throws No Such Element Exception

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.

Answer №1

For the dynamic link id, you can use the following XPath to click on the element:

WebDriverWait(driver, 15).until(EC.visibility_of_element_located((By.XPATH,"//a[contains(text(),'Link')]"))).click();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Modifying Characteristics of Elements Added Dynamically

How do I change the type attribute for dynamically added buttons? In the code below, the label names are changing perfectly, but when I try to change button types, it applies to all dynamically added buttons. My requirement is to change every button type t ...

Tips for integrating the connect-orientdb module with the Express framework

My objective is to establish a connection between my server code, written in nodejs using the expressjs framework, and my database which is built on orientdb. Initially, I aimed to store sessions in the database but encountered difficulties when trying to ...

Exploring the possibilities of event-driven programming with Java and Javascript?

When performing computations on a server, the client inputs data that is captured through Javascript. A XMLHttpRequest is made to send this data to the server for processing. What happens if the computation takes an hour and the client leaves or switches o ...

Limit access to the server in Node.js by allowing loading only if the request is coming from another page and form POST variables are present

After searching for documentation without success, I have a question: Is there a way to prevent users from directly accessing my node.js server at website.com:3000? Currently, when a user visits my node.js website, it crashes the whole server and takes i ...

Unable to arrange an array of JavaScript objects retrieved via an Angular REST request

I'm currently encountering an unusual issue with sorting an array of JavaScript objects. While sorting some dummy data works fine, I am unable to sort the array when fetching the object through an Angular REST call. The structure of the message is as ...

Retrieve the encrypted URL

I'm facing an issue with extracting parameters from an encrypted URL. When using the queryparams function, it only retrieves a portion of the URL after being decrypted. For instance, consider this example URL: http://localhost:4200/househouse? MGRjYjQ ...

Exploring the benefits of using Styled Components for creating global styles in React and Next.js: Should you opt for a mix of CSS files and Styled Components?

Recently, I implemented Styled Components in my Next.js app by following the guidelines from Styled Components. Currently, I am delving into the realm of best practices for managing global styles with Styled Components. The first aspect that piques my curi ...

BufferGeometry is not being displayed

After working extensively with BufferGeometry, I considered myself quite familiar with it. However, I am currently facing an issue while trying to create a simple square plane - there is no visible plane, no errors, and everything seems to be set up correc ...

Unable to create a post request using jQuery with a JSON payload

When using the Chrome REST service, I successfully make a post request to a specific URL by sending a JSON string in the body and setting the content type as application/json. However, when trying to achieve the same with jQuery, I encounter some issues. ...

I constantly find myself being prompted by Chrome to select a download location when using Selenium Hub/Driver in Python

During my testing, I am encountering an issue where Chrome is repeatedly asking me to select a download location for files that are randomly generated on the back-end with unique names. In order to address this problem, I employ specific preferences that ...

Using ui-grid to show cells as drop-down menus

I have a ui-grid example where one of the columns represents gender ('Gender': male, female...). The json data binding to the grid only contains code types like (1, 2, 3...). However, I want to display the gender name such as 'male' if ...

Is it possible to alter the canvas origin when using an Orthographic camera with a CSS3D

When transitioning the camera from perspective to orthographic, I noticed that the camera's position also shifts so that the coordinates 0,0,0 are situated in the top left corner. Is this expected behavior? Check out this Example for reference. Ortho ...

Setting up geckodriver exclusively through the command line

I have a headless ubuntu system and I need to install the latest geckodriver. To do this, I know I need to use a command line as my ubuntu version is 14.04 trusty. However, I am unsure of the specific command needed to install geckodriver. You can find ...

Is it possible to use a hash map to monitor progress while looping through this array in JavaScript?

I've been exploring some algorithmic problems and I'm puzzled about the most efficient way to solve this particular question. While nested for loops are an option, they don't seem like the optimal choice. I'm considering using a hash ma ...

When I try to access localhost, it directs me to http://localhost:3000/myprofile%20 instead of localhost:/3000/myprofile

Every time I try to log into my profile page with the correct login credentials, I get redirected to http://localhost:3000/myprofile%20, but then receive a 404 error. This is what my code looks like: // Login Route router.post('/login', functi ...

The reason why setting height to 0 is ineffective in a CSS definition

Within my current project, I am utilizing vue.js 2 and have implemented an img component. Below is the code for this component: <template> <div class="banner"> <img class="banner-img" :src="bannerImg"/> </div> </template> ...

How can Vue be used to dynamically alter a string within an input field by incorporating the status of checked checkboxes?

Yesterday, I stumbled upon a concise Vue presentation on YouTube before answering a technical question on Stack Overflow. The question involved generating checkbox elements based on a string of text containing '1's and '0's, with the ch ...

Having issues with inline conditional statements in Angular 5

There is a minor issue that I've been struggling to understand... so In my code, I have an inline if statement like this: <button *ngIf="item?.fields?.assetType !== 'tool' || item?.fields?.assetType !== 'questions'">NEXT< ...

Is it possible to create an <h1> heading that can be clicked like a button and actually do something when clicked?

I am currently designing a web page that includes <div class="cane-wrap"> <h1 class="mc">christmas tic tac toe</h1> </div> located at the top center of the webpage, with autoplay running in the backgroun ...

Disappear the loading icon once all children have finished rendering

I'm facing a minor issue with rendering in React and struggling to find a solution. Here's what's happening: My component acts as a wrapper for multiple entries, like this: class MyWrapper extends Component { renderItems() { return ( ...