1
  1. For this code need a css-selector, x-path is available
  2. Following is the x-path such as:

    //div[@class='item-display-name' and text()='edit']
    

HTML of the element:

 <div class="item-display-name">edit</div>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    There is no css selector that lets you select an element based on innerHTML. However, you can select all elements by class name and check if the innerHTML matches your string using JavaScript, as described here https://stackoverflow.com/a/4812052/12690946 – Victor Jun 18 '20 at 13:39

1 Answers1

0

To locate the element you need to induce WebDriverWait for the visibility_of_all_elements_located() and you can use the following based Locator Strategy:

element = WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "div.item-display-name")))

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

Update

As per your comment, No you can't include the text edit within the . You can find a detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I also want to include text "edit " into the selector , for this css-selector there are 7 more results. –  Jun 18 '20 at 13:34
  • @nikhilcodes Checkout the answer update and let me know the status. – undetected Selenium Jun 18 '20 at 13:44
  • How to convert this xpath-- "//*[contains(text(),'$type')] into Selenide css selector –  Jun 18 '20 at 14:45
  • @nikhilcodes Seems like a different question all together. Feel free to raise a new question as per your new requirement. Stackoverflow contributors will be happy to help you out. – undetected Selenium Jun 18 '20 at 14:50