Home > other >  Can't select Review button
Can't select Review button

Time:06-22

I'm making a simple bot to apply to jobs on LinkedIn easy apply. Usually after clicking apply you fill in the basic info and the next button appears until you have a review button and then a submit application button. I was able to click next using a while loop with this code.

button = driver.find_element_by_css_selector(".artdeco-button--primary") while button: button.click() time.sleep(1.25)

but I get this error when the Review button appears

selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document (Session info: chrome=102.0.5005.115)

I've tried a lot of different methods, XPath, WebdriverWait, and others but nothing works to click on the Review button with the following element HTML

<button aria-label="Review your application" id="ember562" type="button"> <span ></span> </button>

could I get some help figuring out how to select the Review button?

CodePudding user response:

DOM Issue:

This probably has to do with the element not being attached to the DOM. See Selenium Docs on this error.

A common technique used for simulating a tabbed UI in a web app is to prepare DIVs for each tab, but only attach one at a time, storing the rest in variables. In this case, it's entirely possible that your code might have a reference to an element that is no longer attached to the DOM (that is, that has an ancestor which is document.documentElement).

If WebDriver throws a stale element exception in this case, even though the element still exists, the reference is lost. You should discard the current reference you hold and replace it, possibly by locating the element again once it is attached to the DOM.

For your particular example, add the button variable inside your while loop. This will have the button variable be re-referenced each time you click which will make it a part of the current DOM.

  • Related