Home > Back-end >  Python Selenium _ Error: selenium.common.exceptions.TimeoutException _ with WebDriverWait
Python Selenium _ Error: selenium.common.exceptions.TimeoutException _ with WebDriverWait

Time:03-06

I'm studying how Selenium works. There are some elements that are fully loaded, but can't be clickable. Here's the example of the case. Selenium took a time until it is fully loaded. But Still the button is not clickable. I think Selenium can't find the element. How can I resolve this issue?

FYI, a pop up is loaded when I click the button manually. Thank you very much for your assistance

url

https://cafe.naver.com/codeuniv

my python code

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

driver = webdriver.Chrome()
driver.get("https://cafe.naver.com/codeuniv")
time.sleep(1)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="menuLink107"]'))).click()
time.sleep(1)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="upperArticleList"]/table/tbody/tr[1]/td[2]/div/table/tbody/tr/td/a'))).click()

button

<a href="#"  onclick="ui(event, 'ftKPZDy0W2UYCbEIxQ-50g',3,'코뮤','30026525','', 'false', 'true', 'codeuniv', 'false', '107'); return false;">코뮤</a>

ERROR

Traceback (most recent call last):
  File "C:\project\naver.py", line 12, in <module>
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="upperArticleList"]/table/tbody/tr[1]/td[2]/div/table/tbody/tr/td/a'))).click()
  File "C:\project\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 89, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

CodePudding user response:

You can use implicity wait that solve your problem or try to id id or other xpath Or try to find iframe

CodePudding user response:

wait=WebDriverWait(driver,10)
driver.get("https://cafe.naver.com/codeuniv")
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="menuLink107"]'))).click()
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID,'cafe_main')))
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="upperArticleList"]/table/tbody/tr[1]/td[2]/div/table/tbody/tr/td/a'))).click()

Your element is in an iframe please wait and switch to it.

<iframe name="cafe_main" id="cafe_main" title="카페 메인" src="//cafe.naver.com/MyCafeIntro.nhn?clubid=30026525" width="860" height="100%" frameborder="0" scrolling="no" marginwidth="0" marginheight="0" allowtransparency="true" allowfullscreen="" style="height: 2140px;" cd_frame_id_="3e06a515dca2ac262583e8ce3ea0e356"></iframe>

Imports:

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