Searching element By xpath return 'script' as tag name

739 views
Skip to first unread message

Vladimir Li

unread,
Aug 1, 2012, 2:21:35 AM8/1/12
to seleniu...@googlegroups.com
driver.findElement(By.xpath("//div[contains(text(), 'text')]")).getTagName return script, what's the problem?

Peter Gale

unread,
Aug 1, 2012, 3:46:07 AM8/1/12
to Selenium Users
Probably the first tag that it's finding is called script, probably one like this:

    <script type="text/javascript">
... near the top of your page.

You'll need to be more specific with your choice of XPath expression.


Date: Tue, 31 Jul 2012 23:21:35 -0700
From: vladim...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] Searching element By xpath return 'script' as tag name


driver.findElement(By.xpath("//div[contains(text(), 'text')]")).getTagName return script, what's the problem?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/_WRsN51xTtIJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Vladimir Li

unread,
Aug 1, 2012, 3:50:44 AM8/1/12
to seleniu...@googlegroups.com
But, there's no div element inside script tag, why is it found

среда, 1 августа 2012 г., 13:46:07 UTC+6 пользователь PeterJef...@Hotmail.co.uk написал:
Probably the first tag that it's finding is called script, probably one like this:

    <script type="text/javascript">
... near the top of your page.

You'll need to be more specific with your choice of XPath expression.


Date: Tue, 31 Jul 2012 23:21:35 -0700
From: vladim...@gmail.com

Subject: [selenium-users] Searching element By xpath return 'script' as tag name

driver.findElement(By.xpath("//div[contains(text(), 'text')]")).getTagName return script, what's the problem?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

Peter Gale

unread,
Aug 1, 2012, 3:56:41 AM8/1/12
to Selenium Users
We can't tell anything unless you show us your full html.


Date: Wed, 1 Aug 2012 00:50:44 -0700
From: vladim...@gmail.com
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Searching element By xpath return 'script' as tag name
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/kPCLoOUyuxkJ.

Stefan Teixeira

unread,
Aug 1, 2012, 7:44:57 PM8/1/12
to seleniu...@googlegroups.com
I recommend you to use Firebug + Xpather (two Firefox addons) when developing Selenium tests.

You could put that xpath in Xpather, so you'll know the elements that refer to it.

2012/8/1 Vladimir Li <vladim...@gmail.com>
driver.findElement(By.xpath("//div[contains(text(), 'text')]")).getTagName return script, what's the problem?

--

anji prassana

unread,
Aug 1, 2012, 11:37:35 PM8/1/12
to seleniu...@googlegroups.com
>>driver.findElement(By.xpath("//div[contains(text(), 'text')]")).getTagName
 
perhaps, You might have constructed the above xpath by looking into an element of your interest;exists at somewhere in your application. But, There might be a chance of having more than one element matches with your Xpath in the entire DOM Tree.So, Selenium will always returns the element that matches first.As stefan said in the earlier comment use Firepath or xpather add-ons to firefox and search your xpath to see which element(s) the xpath you have constructed being matched.So, correct your xpath so that it would match the element of your interest uniquely.
Also, if you are matching the 'div' element whose text is 'text'. Better, to refine your xpath as.
 driver.findElement(By.xpath("//div[text()='text'])).getTagName
 
Thanks&Regards,
Anjaneyulu P
"The Wa you see is the way you think and is the way you react'
--
Thanks&Regards
Anjaneyulu P
"The way you see the things is the way to think and is the way to react upon!!"

Reply all
Reply to author
Forward
0 new messages