0

After about a month of creating and ironing out my Selenium automated tests, I finally added it to a Jenkins pipeline. I didn't expect it to succeed on the first try, but I didn't expect to get errors I've never had happen before, after running these tests hundreds of times.

Suddenly I'm getting stale element errors from an element that just became visible and was just referenced.

# Wait until table shows up
WebDriverWait(self.driver, 10).until(ec.visibility_of_element_located((By.XPATH,'//*[@id="popup-modal-container"]/div[2]/div[2]/div/table/tbody/tr[1]/td[2]')))
# Interact with checkboxes
check_checkbox = self.driver.find_element_by_xpath('//*[@id="popup-modal-container"]/div[2]/div[2]/div/table/tbody/tr[1]/td[1]')
check_checkbox.click()

Like in this code here, I'm getting a staleness error thrown on check_checkbox.click() despite waiting for the html element it's on to be fully present and rendered. Nothing happens to that element until I've told Selenium to click the checkbox. But it's being called stale by Selenium.

In the meantime, I've added an expected condition to wait for that element to be visible, but I doubt that will be more than a hotfix due to all the staleness errors that are suddenly being thrown.

hover_over = WebDriverWait(self.driver, 30).until(ec.visibility_of_element_located((By.ID, 'pl-item-enrollment')))
hover = ActionChains(self.driver).move_to_element(hover_over)
hover.perform()

In the above code, I'm getting a staleness error on the hover.perform(). Similarly, it was just made visible and just referenced, but it's considered stale. Why? I've never gotten this issue before with my navigation tests.

I know Headless Chrome is finicky compared to having the actual browser run, but I haven't managed to get Jenkins to run in a non-headless mode despite trying several suggestions mentioned here.

Advising me how to avoid this sudden staleness or getting Jenkins to actually run the browser would be appreciated, thank you.

2
  • Have you ran your scripts on the slave directly without Jenkins and tried ? Don't always doubt your scripts . Doubt the environment, headless browser isn't flaky it is just faster than normal browser.
    – PDHide
    Apr 29, 2020 at 19:36
  • 1
    First try to run your scripts in both headless and gui mode on the agent directly
    – PDHide
    Apr 29, 2020 at 19:36

1 Answer 1

0

Have you ran your scripts on the slave directly without Jenkins and tried? Don't always doubt your scripts . Doubt the environment, the headless browser isn't flaky it is just faster than normal browser.

First, try to run your scripts in both headless and GUI mode on the agent directly without Jenkins

The thing that makes your test flaky is your xpath, don't use such absolute xpaths . It will break now or later as UI changes ( when someone adds more elements) . Use locators that are easily identifiable and unique.

1
  • 1
    I didn't have a slave set up, so I created that after I confirmed I could run the tests without Jenkins. Specifically, I had to set the slave's launch method to be 'Launch agent by connecting it to the master'.
    – due_rest
    May 1, 2020 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.