OCLCrimson
OCLCrimson

Reputation: 11

Element Not Visible from Modal Window - Selenium Python

I'm trying to log in to a webpage so that I can scrape data from it, but every time I try, i get the error Element Not Visible. The element I'm trying to click is a button inside of a modal window, but the html for that window only appears after a login button is clicked. I can click the login button, but I can't click the teacher button that pops up afterwards. Any ideas?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

login_url = 'https://edpuzzle.com/'
username = '***'
password = '***'
ChromeDriver = r'C:\Users\admin\Python\chromedriver.exe'

driver = webdriver.Chrome(ChromeDriver)
driver.get(login_url)
driver.find_element_by_css_selector('button.btn.btn-default-
transparent').click()
driver.find_element_by_css_selector('p.modal-title.text-lg.text-center.edp-
role-title')
driver.find_element_by_css_selector('button.btn.white-btn.btn-lg.btn-
block.big-btn.edp-teacher-role').click()

Upvotes: 1

Views: 1605

Answers (1)

Andersson
Andersson

Reputation: 52695

You're trying to click button before it actually visible. You need to wait some time:

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

driver.get(login_url)
driver.find_element_by_id('edp-login').click()
wait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "button.btn.white-btn.btn-lg.btn-block.big-btn.edp-teacher-role"))).click()

Upvotes: 1

Related Questions