Issue 5459 in selenium: InvalidSelectorError: The result of the xpath expression is: [object Text]

167 views
Skip to first unread message

sele...@googlecode.com

unread,
Apr 7, 2013, 3:47:56 AM4/7/13
to selenium-develope...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium Status-Untriaged

New issue 5459 by vishal...@gmail.com: InvalidSelectorError: The result
of the xpath expression is: [object Text]
http://code.google.com/p/selenium/issues/detail?id=5459

Here is the html source code of the page:

<!DOCTYPE html>
<html>
<body>

<form action="">
<input type="radio" name="sex" value="female">Male<br>
<input type="radio" name="sex" value="male">Female
</form>

<p><b>Note:</b> When a user clicks on a radio-button, it becomes checked,
and all other radio-buttons with equal name become unchecked.</p>

</body>
</html>


http://www.w3schools.com/html/tryit.asp?filename=tryhtml_radio

What steps will reproduce the problem?
1. Open the application using selenium webDriver

FirefoxDriver Browser = new FirefoxDriver();
Browser.get("http://www.w3schools.com/html/tryit.asp?filename=tryhtml_radio");



2. Read the text/label of the radio button whose html attribute
value="female"
String XPATH = "//input[@value='female']/following-sibling::text()"
String LABEL = Browser.findElement(By.xpath(XPATH)).getText();

3. An InvalidSelectorError exception is raised by WebDriver:
Exception in thread "main" org.openqa.selenium.InvalidSelectorException:
The given selector //input[@value='Red']/following-sibling::text() is
either invalid or does not result in a WebElement. The following error
occurred:
InvalidSelectorError: The result of the xpath
expression "//input[@value='Red']/following-sibling::text()" is: [object
Text]. It should be an element.

This works fine with Selenium IDE and RC but not with WebDriver.

What is the expected output? What do you see instead?
Ideally it should return the label of the radio button

Selenium version: 2.31.0
OS: Windows XP Professional SP2
Browser: FireFox
Browser version: 19.0.2


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

sele...@googlecode.com

unread,
Apr 7, 2013, 10:29:36 AM4/7/13
to selenium-develope...@googlegroups.com
Updates:
Status: WorkingAsIntended
Labels: -Status-Untriaged

Comment #1 on issue 5459 by james.h....@gmail.com: InvalidSelectorError:
The result of the xpath expression is: [object Text]
http://code.google.com/p/selenium/issues/detail?id=5459

Your xpath doesn't return an element; it returns a text node. While this
might have been perfectly acceptable in Selenium RC (and by extension,
Selenium IDE), the methods on the WebDriver WebElement interface require an
element object, not just any DOM node object. WebDriver is working as
intended. To fix the issue, you'd need to change the HTML markup to wrap
the text node inside an element, like a <span>.

sele...@googlecode.com

unread,
Oct 21, 2013, 3:26:06 PM10/21/13
to selenium-develope...@googlegroups.com
Updates:
Cc: Samit.Badle

Comment #2 on issue 5459 by barancev: InvalidSelectorError: The result of
the xpath expression is: [object Text]
http://code.google.com/p/selenium/issues/detail?id=5459

Issue 3635 has been merged into this issue.

sele...@googlecode.com

unread,
Oct 21, 2013, 3:27:06 PM10/21/13
to selenium-develope...@googlegroups.com

Comment #3 on issue 5459 by barancev: InvalidSelectorError: The result of
the xpath expression is: [object Text]
http://code.google.com/p/selenium/issues/detail?id=5459

Issue 2871 has been merged into this issue.

sele...@googlecode.com

unread,
Jan 7, 2014, 11:04:55 AM1/7/14
to selenium-develope...@googlegroups.com

Comment #4 on issue 5459 by chandra...@gmail.com: InvalidSelectorError: The
result of the xpath expression is: [object Text]
http://code.google.com/p/selenium/issues/detail?id=5459

You can use this code :

FoundObjectCount =
FindWebElementCount(ieDriver,"xpath", "//input[@type='radio' and
(contains(@name,'XXX'))]");

for(int objcnt = 1; objcnt <= FoundObjectCount; objcnt++) {

FoundObject =
ieDriver.findElement(By.xpath(".//table[@class='XXX']/tbody/tr["+objcnt+"]/td/label"));

if (FoundObject.getText().equalsIgnoreCase(strSalecycle)) {
FoundObject =
ieDriver.findElement(By.xpath(".//table[@class='XXX']/tbody/tr["+objcnt+"]/td/input"));
ObjectClick(FoundObject);
LogInfo("WebElement is Selected of Object id
is: "+FoundObject.getAttribute("id"));
break;
} else{
LogInfo("WebElement is Not Present in UI");
break;
}

When the HTML looks like this:

<Table>
<TR>
<TD><INPUT id=XXX value="JUNK" type=radio name=ABCXXX><LABEL
for=idXXX>TEXTNEEDTOREAD1 </LABEL>
</TD>
</TR>
<TR>
<TD><INPUT id=XXX value="JUNK" type=radio name=ABCXXX><LABEL
for=idXXX>TEXTNEEDTOREAD2 </LABEL>
</TD>
</TR>
</Table>

sele...@googlecode.com

unread,
Sep 22, 2014, 4:52:31 AM9/22/14
to selenium-develope...@googlegroups.com

Comment #5 on issue 5459 by rizalyn....@gmail.com: InvalidSelectorError:
The result of the xpath expression is: [object Text]
https://code.google.com/p/selenium/issues/detail?id=5459

Any updates regarding this issue?

sele...@googlecode.com

unread,
Sep 22, 2014, 5:17:54 AM9/22/14
to selenium-develope...@googlegroups.com

Comment #6 on issue 5459 by arran.hu...@gmail.com: InvalidSelectorError:
The result of the xpath expression is: [object Text]
https://code.google.com/p/selenium/issues/detail?id=5459

This is a "working as intended" issue, so if you've got any sample pages or
code that could help prove otherwise then you'll need to post them -
otherwise there is literally nothing anybody can do because the only piece
of code and reproducible material someone has given has proven WebDriver
*is* working as it's intended to do.

sele...@googlecode.com

unread,
Jan 26, 2015, 8:18:47 AM1/26/15
to selenium-develope...@googlegroups.com

Comment #7 on issue 5459 by vinod.ko...@zenq.com: InvalidSelectorError: The
result of the xpath expression is: [object Text]
https://code.google.com/p/selenium/issues/detail?id=5459

http://only-testing-blog.blogspot.in/2014/01/textbox.html

I want to retreive and verify for the label 'First name' in the above
page.I've used below
String
s3=d.findElement(By.xpath(".//text()[followingsibling::input[@name='fname']]")).getText();



Im getting

Caused by: org.openqa.selenium.InvalidSelectorException: The given
selector .//text()[following-sibling::input[@name='fname']] is either
invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: The result of the xpath
expression ".//text()[following-sibling::input[@name='fname']]" is: [object
Text]. It should be an element.
For documentation on this error, please visit:
http://seleniumhq.org/exceptions/invalid_selector_exception.html

pleasee help me out
Reply all
Reply to author
Forward
0 new messages