How to retrieve text from an element using Selenium WebDriver and Java

Denis S. :

I'm trying to retrieve text of an element with == $0. I tried to use JS injection ((JavascriptExecutor) driver).executeScript("return arguments[0].value", driver.findElement(By.cssSelector("div.settings span"))) but this approach returns NULL for me enter image description here

DebanjanB :

As the texts Shooting and Pedestrian Accident are within elements which are text nodes, so to extract the texts you can use the following solutions:

WebElement myElement = driver.findElement(By.cssSelector("div.settings")); 
//extracting Shooting
System.out.println(((JavascriptExecutor)driver).executeScript("return arguments[0].firstChild.textContent;", myElement).toString());
//extracting Pedestrian Accident
System.out.println(((JavascriptExecutor)driver).executeScript("return arguments[0].lastChild.textContent;", myElement).toString());

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to retrieve part of a text of an element using Selenium WebDriver and Python?

How to get element(text) from a table using Selenium WebDriver with Python

How to get the text from mouseover popup element using Selenium Webdriver

How to get the actual text from a span element enclosed within multiple span tags, using Selenium Webdriver with Java

Using selenium webdriver python to retrieve SVG text element

How to retrieve an attribute of a react element inside a class using selenium webdriver?

Verify text - innerHTML from element using Selenium webdriver with python

How to extract the text from the element using Selenium through Java

How to extract the text within the element using Selenium WebDriver and Python?

How to read text from hidden element with Selenium WebDriver?

how to select an element from autoselect drop down in GoIbibo from city field using selenium webdriver java

How to select a web element by text with Selenium WebDriver, Java

How to retrieve text of an element without tag using following child in Selenium

How to retrieve partial text from a text node using Selenium and Python

Find Element By Text Using Selenium WebDriver

How to access invisible Unordered List element with Selenium WebDriver using Java

how to get text from image logo on Login page using Selenium Webdriver with java

How to extract the text of the firstselectedoption from a dropdown using Selenium Webdriver through Java

How to print the text using a locator from the span in selenium webdriver python?

How to get text from tooltip with no attributes using Selenium Webdriver with Python?

How to type some text in hidden field in Selenium WebDriver using Java

How to extract the text of the outer span using Selenium WebDriver and Java

How to wait for an element NOT to be clickable using Selenium Webdriver?

How to double click on an element using Selenium Webdriver

How to click an element in Selenium WebDriver using JavaScript

How to click on this web element using selenium webdriver?

How to extract the link from selenium webdriver element?

How to find an Element by index in selenium webdriver for java

Using Selenium Webdriver how to retrive date text

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive