Ask a Question

how to Get Text from Element

gsgowtam
New Member

how to Get Text from Element

HI,

 

I need to get Text from the element, 
can someone help me that how to get the text from the element?

 Here my scenario is: I need to verify whether the column values in the table are in descending order or not.


gsgowtam_0-1652953309957.png

 

I was tried in two different ways

1. let val1=sys.Browser("chrome").Page(pageURL).Findelements("xpath=locator").Text;

Error: Text is not a function

2. let val1 = document.querySelector("CssSelector").innerText

Error: document is undefined
Note: Here I'm trying this in Script mode

1 REPLY 1
npaisley
Staff

Hi @gsgowtam!

 

One of the most common methods to retrieve the text of an object is to the retrieve the 'contentText' of an object. 

 

For instance, I can retrieve the text of our Login button on our SmartStore with the snippet below;

loginButtonText = Aliases.browser.Page("https://bearstore-testsite.smartbear.com/").FindElement("//span[.='Log in']").contentText;

 

Here is our document on the contentText Property;

https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/web-objects/contentte...

 

I hope this helps!


Regards,
Nick

Solutions Engineer @ SmartBear
cancel
Showing results for 
Search instead for 
Did you mean: