- rohit kumar guptaActive particpant
- Posts : 24
Join date : 2012-09-19
Age : 34
Location : abc
Dynamic webelement verification
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">
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">
- popshaAmateur
- Posts : 60
Join date : 2012-04-14
Re: Dynamic webelement verification
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,
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.
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 guptaActive particpant
- Posts : 24
Join date : 2012-09-19
Age : 34
Location : abc
Re: Dynamic webelement verification
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.
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.
Re: Dynamic webelement verification
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());
- popshaAmateur
- Posts : 60
Join date : 2012-04-14
Re: Dynamic webelement verification
Wed Nov 07, 2012 10:34 am
Yes, tarun is correct.
- rohit kumar guptaActive particpant
- Posts : 24
Join date : 2012-09-19
Age : 34
Location : abc
Re: Dynamic webelement verification
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...
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...
- popshaAmateur
- Posts : 60
Join date : 2012-04-14
Re: Dynamic webelement verification
Wed Nov 07, 2012 2:35 pm
can achieve this in different ways by hard coding it.
try using .equals method
try using .equals method
Permissions in this forum:
You cannot reply to topics in this forum