0

I have an "onclick" element in a webpage whose HTML reads as follows:

<a href="#" onclick="blah.submit()">Text 1</a>

I am trying to use selenium to click on this element. I tried the following code (including an implicit wait)

import time
from selenium import webdriver

driver = webdriver.Chrome()
driver.get(webpage);

driver.implicitly_wait(5)
driver.find_element_by_xpath("//a[@onclick='blah.submit()']").click()    

However, it returned a NoSuchElementException

NoSuchElementException: Message: no such element: Unable to locate element: 
{"method":"xpath","selector":"//a[@onclick='blah.submit()']"}

I then tried using WebDriverWait

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(webpage);

button = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, 
"//a[@onclick='blah.submit()']")))
button.click()

However, this still didn't work and returned the following error:

TimeoutException: Message:

Does anyone know what's going wrong? Thanks in advance.

0 Answers0