0

I'm getting this error when I run this Python/Selenium script.

File "./a.py", line 21, in <module>
elem = driver.find_element_by_id("licensees").click()
 raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: 

Here is the html code

<p>
 <button onClick="myloginwindow1('')" value="Login Now" name="licensees" id="licensees">
 <p>Licensee Login</p>
</button> 
</p>

Here is the code.

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
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("https://xxxxx.com")
assert "xxxxxxxx" in driver.title
try:
element = WebDriverWait(driver, 30).until(
 EC.presence_of_element_located((By.ID, "licensees"))
)
elem = driver.find_element_by_id("licensees").click()
finally:
 driver.quit()

When I remove

elem = driver.find_element_by_id("licensees").click()

I don't get an error.

asked Jan 16, 2017 at 22:38
0

3 Answers 3

2

You can also execute the script that's executed when clicking the button. This way you won't need to wait for the element to be clickable.

 driver.execute_script(
 "myloginwindow1('')"
 )
answered Jun 16, 2019 at 15:06
Sign up to request clarification or add additional context in comments.

Comments

0

Use visibilityOfElementLocated instead of presence_of_element_located

presenceOfElementLocated don't care whether if element visible or not, It just checks element is on the page

try:
 WebDriverWait(driver, 60).until(EC.visibility_of_element_located((By.ID, "licensees"))).click()
answered Feb 2, 2017 at 14:01

Comments

0

As mentioned elsewhere, presence is different than visibility.

But with capybara-py, you don’t have to think about either:

from capybara.dsl import page
page.visit("...")
page.assert_title("...")
page.click_button("Licensee Login")

Here, click_button() waits for the button to be interactable.

(Similarly, assert_title() waits for the title to match, in case, e.g., the page takes a while to fully load.)

answered Feb 7, 2018 at 16:42

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.