1

I need to check if we something with on the page as a trigger:

data-id="false_5511971198499@c.us_DBC6E6D07C76B179C26A40D689B2AEB2"

But, I need to check only "data-id="false_" because the rest could be anything.

I tried to create:

element = driver.find_element_by_xpath("[data-id='False']")

But didn't worked. And I don't know how to continue like if there is this element we need to print(ok).

Could you help me?

Thank you!

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • element = driver.find_element_by_xpath("[data-id='False']") this function is not working searching for: data-id="false_5511971198499@c.us_DBC6E6D07C76B179C26A40D689B2AEB2" – Victor Maihato Jul 09 '20 at 21:19

2 Answers2

0

Try this

//*[starts-with(@data_id,'false_')]
Amruta
  • 1,128
  • 1
  • 9
  • 19
0

It's a dynamic element so you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using XPATH:

    WebDriverWait(browser, 20).until(EC.visibility_of_element_located((By.XPATH, "//*[starts-with(@data-id, 'false_')]")))
    
  • Using CSS_SELECTOR:

    WebDriverWait(browser, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[data-id^='false_']")))
    
  • 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