Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract the text within an HTML tag (in Selenium IDE)?

Tags:

selenium

The html looks something like this:

<p>
    sometext1
    <br>
    sometext2
    <br>
    sometext3
</p>

I would like to extract all the text between the paragraph tags, including the <br> tags.

I tried to use storeText function, but it stores only the text, without the tags. I could store the entire HTML source and then extract what I need in Perl, but I was wondering if there is a way to store a block of HTML code using a specific xpath (e.g. store the HTML code for the third table in the webpage inside a variable).

like image 261
Alex Avatar asked May 20 '11 09:05

Alex


People also ask

How to extract text from Selenium?

We can extract text from a webpage using Selenium webdriver and save it as a text file using the getText method. It can extract the text for an element which is displayed (and not hidden by CSS).

How to getText from Webpage in Selenium?

We can get the text from a website using Selenium webdriver USING the getText method. It helps to obtain the text for a particular element which is visible or the inner text (which is not concealed from the page).

What is DOM locator in Selenium?

DOM stands for Document Object Model. In simple words, DOM specifies the structural representation of HTML elements. There are four ways through which we can identify and locate a web element using DOM.


1 Answers

innerHTML

i will try with document.getElementById('id').innerHTML

like image 99
sisi Avatar answered Oct 01 '22 10:10

sisi