1

I'm trying to click on a button, but selenium can't find the element.

enter image description here

I'm using the xpath:

//button[@title="Monitor Chart(Ctrl+Alt+G)"]

but selenium can't locate. I can find the xpath from Chrome manualy using the find(Ctrl+F) tool, as we can see in the image.

Here is my code and error. The xpath does't have an ID.

Code Snapshot:

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Breno1982
  • 45
  • 4

3 Answers3

2

To click on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.eui-btn.eui-btn-default.eui-btn-normal[title^='Monitor Chart']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='eui-btn eui-btn-default eui-btn-normal' and starts-with(@title, 'Monitor Chart')]"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Thanks a lot. I figure it out the issue. the button was inside an iframe. But you solution gave me an idea to another issues that I was having. Instead of use timesleep function, I'm gonna use your solution with WebdriverWait – Breno1982 Jul 29 '22 at 12:56
1
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

hiding_button = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[title ='Monitor Chart(Ctrl+Alt+G)']")))
hiding_button.click()
Barry the Platipus
  • 9,594
  • 2
  • 6
  • 30
0

Thanks to all. But I figure it out the issue. The button was inside an iFrame. So I hadd to switch to the iFrame first.

Code used:

iframe = driver.find_element_by_id('Access_Performance_Monitor')
driver.switch_to.frame(iframe)
cottontail
  • 10,268
  • 18
  • 50
  • 51
Breno1982
  • 45
  • 4