Skip to content
This repository was archived by the owner on Nov 29, 2018. It is now read-only.
This repository was archived by the owner on Nov 29, 2018. It is now read-only.

InvalidSelectorError: The result of the xpath expression is: [object Text] #5459

@lukeis

Description

@lukeis

Originally reported on Google Code with 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>Note: 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

Reported by vishalkharge on 2013-04-07 07:47:52

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions