1

I am trying to click a save button via selenium, however, I am getting the error that it is unable to locate the element.

this is the html part of the website

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get("xxx")

WebDriverWait(driver,10).until(EC.presence_of_element_located(driver.find_element_by_id("DivFlashViewerMain_SavePdfButtonIcon")))
driver.find_element_by_xpath('//*[@id="DivFlashViewerMain_SavePdfButtonIcon"]').click()

This is the error I am getting:

NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"DivFlashViewerMain_SavePdfButtonIcon"}
(Session info: chrome=74.0.3729.169) (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17763 x86_64)

2 Answers 2

1

You should use element_to_be_clickable not just presence_of_element_located.

It should look something like this:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get("xxx")

button = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID, "DivFlashViewerMain_SavePdfButtonIcon")))
button.click()

Hope this helps!

Sign up to request clarification or add additional context in comments.

1 Comment

This should nail the OP.
1
driver.find_elements_by_css_selector('[id="DivFlashViewerMain_SavePdfButtonIcon"]')[0].click()

Seems like you are using a lot of functions, example for locating id="". Highly recommend trying css-selectors: How to use querySelectorAll only for elements that have a specific attribute set?

1 Comment

Using CSS-selectors is highly recommend... yet I think OP's issue is with waiting for presence_of_element_located any way +1! ;)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.