Reputation: 127
I'm trying to click on this button shown below named “Segment Metrix 2.0 Consumer Target Profile report“
and I found corresponding HTML as shown below.
I tried to write code as below:
elem = driver.find_elements_by_xpath("//*[contains(text(), 'Segment Metrix 2.0 Consumer Target Profile report ')]")
print (elem)
it gives me:
[<selenium.webdriver.remote.webelement.WebElement (session="daf65f4e5ed0485027d04eed8db8aca7", element="0.8079987809618281-1")>]
But I can't click on it by adding elem[0].click()
, it throws me an "element not visible" error. What should I do?
Upvotes: 2
Views: 650
Reputation: 4267
The problem is that the element has to be visible. It means that even if it's in html, it's not enough, it has to been visible from the browser. Try to click on the dropdown first in order to see its elements and only than click on one of the elements. Also, after clicking on the dropdown, don't forget to wait until your element will be seen, either explicitly or implicitly.
Do you sure you need to click on it? If it is just an object with an url, exact the url and use driver.get(url)
Upvotes: 1
Reputation: 50809
You can wait for the element to be visible
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
elem = driver.find_elements_by_xpath("//*[contains(text(), 'Segment Metrix 2.0 Consumer Target Profile report ')]")
WebDriverWait(driver, 10).until(EC.visibility_of(elem[0]))
elem[0].click()
Upvotes: 0
Reputation: 52665
Try to wait until element become visible:
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
wait(driver, 10).until(EC.visibility_of_element_located((By.LINK_TEXT, "Segment Metrix 2.0 Consumer Target Profile report"))).click()
Upvotes: 0