Reputation: 473
I'm trying to click on an element containing the phone number on this site, link down below. It's the element which says "Toon Nummer"
Finding the element is easy enough:
tel = driver.find_element_by_xpath("//button[contains(@title, 'telefoon')]")
But if I want to click it, so far I know two ways:
tel.click()
This just returns ElementNotVisibleException. And the other way:
driver.execute_script("arguments[0].click();", tel)
This just doesn't do anything, no error but no click either because the information doesn't get displayed. What else can I do to successfully click on this?
link to site
Upvotes: 1
Views: 9448
Reputation: 193298
To click on the element with text as Toon nummer you have to induce WebDriverWait for the element to be clickable and you can use the following solution:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# other lines of code
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//aside[@class='l-side-right']//button[@class='mp-Button mp-Button--secondary' and @title='Toon telefoonnummer']//span[contains(.,'Toon')]"))).click()
Upvotes: 0
Reputation: 29372
try this :
phone_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//div[@id='vip-seller']/following-sibling::section/child::button")))
phone_button .click()
Make sure you are importing these :
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
The Xpath you have written contains two web elements. Hope this will help.
Upvotes: 1