Selenium : Find nested div with specific plain text using xpath

Bernard 'Beta Berlin' Parah

I need to find a certain text in a nested div that has no class or id.

This is a structure of the html.

<div class="active_row">
  <div class="outcomes">
   <div class="event_outcome" onclick="doSomething">
     <div>Target Text</div>
   </div>
  </div>
</div>

I tried accessing the text directly using the example I got from here.

driver.find_elements_by_xpath("//div[contains(., 'Target Text')]")

This returns a list of elements that contain the target text but nothing happens when I run the click method on them.

What's the best way to set this query to find the text and then click on the div with event_outcome class?

har07

To select the div with event_outcome class, you can add a predicate in your XPath to check class attribute value :

//div[contains(., 'Target Text') and @class='event_outcome']

or add a predicate to check existence of onclick attribute :

//div[contains(., 'Target Text') and @onclick]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Xpath find a div without children with specific text

From Dev

Selenium : Enter the text in div using xpath

From Dev

XPath: Find HTML element by plain text

From Dev

How to find elements through text ignoring the case using Selenium and Xpath

From Dev

How to find elements through text ignoring the case using Selenium and Xpath

From Dev

Using selenium, how to select a the text in a paragraph which is nested in a div element?

From Dev

Get text from nested div tags using selenium webdriver

From Dev

Using jQuery to find list items containing specific text in nested lists

From Dev

Selenium Python Xpath how to select the correct span text from many nested div tags

From Dev

xpath: how to get the specific text using xpath?

From Dev

Find an xml element with some specific text using xpath or find in python using lxml

From Dev

Find element by text in xpath not working - selenium webdriver

From Dev

using xpath to find Href in selenium webdriver

From Dev

Xpath find div with no divs with same text

From Dev

Getting WebElement by Text using XPath in Selenium test

From Dev

How to get plain text with Xpath

From Dev

How to get plain text with Xpath

From Dev

Selenium IDE: Find specific text and press button

From Dev

How to get a specific text from a javascript code in selenium webdriver by xpath

From Dev

Selenium Xpath to find a table cells inside a div tag

From Dev

Selenium Xpath to find a table cells inside a div tag

From Dev

Selenium / xpath - Can't find element, finding parent div

From Java

Find xpath with following-siblings and contains text in Python Selenium

From Dev

Find an element by text and get xpath - selenium webdriver junit

From Dev

Selenium XPath: How to find text within a span class tag?

From Dev

Unable to find xPath in Selenium

From Dev

Run text() of Xpath in selenium

From Dev

Run text() of Xpath in selenium

From Dev

Find Element By Text Using Selenium WebDriver

Related Related

  1. 1

    Xpath find a div without children with specific text

  2. 2

    Selenium : Enter the text in div using xpath

  3. 3

    XPath: Find HTML element by plain text

  4. 4

    How to find elements through text ignoring the case using Selenium and Xpath

  5. 5

    How to find elements through text ignoring the case using Selenium and Xpath

  6. 6

    Using selenium, how to select a the text in a paragraph which is nested in a div element?

  7. 7

    Get text from nested div tags using selenium webdriver

  8. 8

    Using jQuery to find list items containing specific text in nested lists

  9. 9

    Selenium Python Xpath how to select the correct span text from many nested div tags

  10. 10

    xpath: how to get the specific text using xpath?

  11. 11

    Find an xml element with some specific text using xpath or find in python using lxml

  12. 12

    Find element by text in xpath not working - selenium webdriver

  13. 13

    using xpath to find Href in selenium webdriver

  14. 14

    Xpath find div with no divs with same text

  15. 15

    Getting WebElement by Text using XPath in Selenium test

  16. 16

    How to get plain text with Xpath

  17. 17

    How to get plain text with Xpath

  18. 18

    Selenium IDE: Find specific text and press button

  19. 19

    How to get a specific text from a javascript code in selenium webdriver by xpath

  20. 20

    Selenium Xpath to find a table cells inside a div tag

  21. 21

    Selenium Xpath to find a table cells inside a div tag

  22. 22

    Selenium / xpath - Can't find element, finding parent div

  23. 23

    Find xpath with following-siblings and contains text in Python Selenium

  24. 24

    Find an element by text and get xpath - selenium webdriver junit

  25. 25

    Selenium XPath: How to find text within a span class tag?

  26. 26

    Unable to find xPath in Selenium

  27. 27

    Run text() of Xpath in selenium

  28. 28

    Run text() of Xpath in selenium

  29. 29

    Find Element By Text Using Selenium WebDriver

HotTag

Archive