Share
Go down
rohit kumar gupta
Active particpant
Active particpant
Posts : 24
Join date : 2012-09-19
Age : 28
Location : abc

Dynamic webelement verification

on Mon Nov 05, 2012 11:54 am
Hi popsha:-
The line in bold below is what i want to validate.
<div id="main-content">

<div class="module-advert" style="overflow:visible">


<span class="corners-top">

<div class="inner">

<span class="corners-bottom">
</div>

<div style="height:3px"></div>

<p class="right rightside">Your last visit was on Sun Nov 04, 2012 10:11 am</p>

<p>Current date/time is Sun Nov 04, 2012 11:34 pm</p>

<br class="clear">

<ul class="linklist">

<div class="forabg">

<div class="forabg">

<div class="forabg">
<ul class="linklist">
popsha
Amateur
Amateur
Posts : 60
Join date : 2012-04-14

Re: Dynamic webelement verification

on Mon Nov 05, 2012 1:30 pm
Dear Rohit,

As I understand from your code, only the "text" changes and not the web element. It means,

....

is static.

If I'm right, both xpath-relative and xpath-absolute should work in your scenario. Please let me know the errors it throws.

Because I tried this in my tool with similar scenarios.
rohit kumar gupta
Active particpant
Active particpant
Posts : 24
Join date : 2012-09-19
Age : 28
Location : abc

Re: Dynamic webelement verification

on Tue Nov 06, 2012 11:34 am
Hi Popsha,

I am trying this:-

System.out.println(driver.findElement(By.xpath("//div[@id='main-content']/p[2]")).getAttribute("Text"));

but it fetches null.

I tried this with other attributes like name,value but no result.

I was actually thinking if we can pass text as parameter and identify the webelement.
tarun3kumar
Master
Master
Posts : 186
Join date : 2012-02-14
http://seleniumtests.com

Re: Dynamic webelement verification

on Tue Nov 06, 2012 2:26 pm
rohit kumar gupta wrote:Hi Popsha,
System.out.println(driver.findElement(By.xpath("//div[@id='main-content']/p[2]")).getAttribute("Text"));

but it fetches null.

It fetches null because there is no such attribute called - "Text". You need to use getText() method -

Code:
System.out.println(driver.findElement(By.xpath("//div[@id='main-content']/p[2]")).getText());
I assume that your xPath is correct!

_________________
Thanks
Tarun K
Free Selenium Training
popsha
Amateur
Amateur
Posts : 60
Join date : 2012-04-14

Re: Dynamic webelement verification

on Wed Nov 07, 2012 10:34 am
Yes, tarun is correct.
rohit kumar gupta
Active particpant
Active particpant
Posts : 24
Join date : 2012-09-19
Age : 28
Location : abc

Re: Dynamic webelement verification

on Wed Nov 07, 2012 11:43 am
Thanks Tarun and Popsha....

Just another doubt. In doing gettext() i will have to write an if statment to compare texts. Is there a way where in i can pass the text and check for presence of the webelement. Something similar to checkpoint of qtp...
popsha
Amateur
Amateur
Posts : 60
Join date : 2012-04-14

Re: Dynamic webelement verification

on Wed Nov 07, 2012 2:35 pm
can achieve this in different ways by hard coding it.

try using .equals method
Sponsored content

Re: Dynamic webelement verification

Back to top
Permissions in this forum:
You cannot reply to topics in this forum