Skip to content Skip to sidebar Skip to footer

Find A Element Using Selenium Python

I'm new to python and I'm trying to write a web scraping script. I'm trying to double click on this element (it's neither a button nor link - just a td element) and am having troub

Solution 1:

To locate the desired <td> element you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • XPATH 1:

    element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//td[contains(@title, 'Imported') and starts-with(., 'Business Profile')]")))
    
  • XPATH 2:

    element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//td[starts-with(@title, 'Business Profile') and contains(., 'Imported')]")))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.uiimportWebDriverWaitfrom selenium.webdriver.common.byimportByfrom selenium.webdriver.supportimport expected_conditions asEC

Solution 2:

To handle dynamic element induce WebDriverWait and element_to_be_clickable and use the following xpath

WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//td[@title='Business Profile (Imported)' and text()='Business Profile (Imported)']"))).click()

OR

WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//td[@title='Business Profile (Imported)'][contains(.,'Business Profile (Imported)')]"))).click()

You need to imports following to execute above code.

from selenium.webdriver.common.byimportByfrom selenium.webdriver.support.uiimportWebDriverWaitfrom selenium.webdriver.supportimport expected_conditions asEC

Post a Comment for "Find A Element Using Selenium Python"