Home > database >  How to find search area using selenium in python
How to find search area using selenium in python

Time:11-20

I have this html:

<input _wad-f341 type="text" autocomplete="off" kkwdnkwn class="classname" placeholder="Search  here" id="ppui-search-0-input">

Using developer tools I am getting the xpath and I am using below code to check if the search area is loaded or not.

WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.XPATH, "//*[@id='ppui-search-0-input']")))

I am getting timeout as element was not found. Can anyone please help me? Is there any other way apart from id like using the placeholder desription?

CodePudding user response:

Ideally to locate a clickable element instead of presence_of_element_located() you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.classname[placeholder='Search  here'][id^='ppui-search']")))
    
  • Using XPATH:

    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='classname' and @placeholder='Search  here'][starts-with(@id, 'ppui-search')]")))
    
  • 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
    
  • Related