Search code examples
pythonseleniumxpathcss-selectorswebdriverwait

Unable to locate element with id, class_name and xpath using Selenium Python


How to click this button:

picture of element i need info on

I have tried the following:

sumbitbutton = driver.find_element(By.XPATH, "//div[text() = 'mt8 mb8']")

I decided to insted abandon this method and go for a nuther as it lead to a lot of other problums latter down the line


Solution

  • Generally <div> tags aren't clickable. Additionally mt8 mb8 are the classanmes, not the text.


    Solution

    As per the HTML:

    snapshot

    to click on the <input> 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, "input.inputButton.main_submit[value='Submit']"))).click()
      
    • Using XPATH:

      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='inputButton.main_submit' and @value='Submit']"))).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