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

1
  • try copying the full x path from the inspect tab and using that as test_1 Commented Jul 23, 2022 at 13:52

3 Answers 3

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
    
Sign up to request clarification or add additional context in comments.

1 Comment

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

Comments

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.