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>
1
  • 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 stackoverflow.com/a/4812052/12690946 Commented Jun 18, 2020 at 13:39

1 Answer 1

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:

Sign up to request clarification or add additional context in comments.

4 Comments

I also want to include text "edit " into the selector , for this css-selector there are 7 more results.
@nikhilcodes Checkout the answer update and let me know the status.
How to convert this xpath-- "//*[contains(text(),'$type')] into Selenide css selector
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.