Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

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

Dynamic webelement verification Empty 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">
avatar
popsha
Amateur
Amateur
Posts : 60
Join date : 2012-04-14

Dynamic webelement verification Empty 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,

....

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.
avatar
rohit kumar gupta
Active particpant
Active particpant
Posts : 24
Join date : 2012-09-19
Age : 34
Location : abc

Dynamic webelement verification Empty 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.
avatar
tarun3kumar
Master
Master
Posts : 186
Join date : 2012-02-14
http://seleniumtests.com

Dynamic webelement verification Empty 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());
I assume that your xPath is correct!
avatar
popsha
Amateur
Amateur
Posts : 60
Join date : 2012-04-14

Dynamic webelement verification Empty Re: Dynamic webelement verification

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

Dynamic webelement verification Empty 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...
avatar
popsha
Amateur
Amateur
Posts : 60
Join date : 2012-04-14

Dynamic webelement verification Empty 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
Sponsored content

Dynamic webelement verification Empty Re: Dynamic webelement verification

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