Reputation: 11
driver.findElement(By.xpath("//input[@type="+"checkbox"+"]/following-sibling:://td[contains(text(),"+"template"+"]"))
My HTML is like this
<tr>
<td class="tablecontent">
<input type="checkbox" value="59781" name="templateIds">
</td>`enter code here`
<td class="tablecontent"> test11 </td>
</tr>
org.openqa.selenium.InvalidSelectorException: The given selector //input[@type=checkbox]/following-sibling:://td[contains(text(),template] is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: Unable to locate an element with the xpath expression //input[@type=checkbox]/following-sibling:://td[contains(text(),template] because of the following error: [Exception... "The expression is not a legal expression." code: "12" nsresult: "0x805b0033 (SyntaxError)" location: "file:///C:/Users/sanjdash/AppData/Local/Temp/anonymous3529970525380845680webdriver-profile/extensions/[email protected]/components/driver_component.js Line: 5956"] Command duration or timeout: 72 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html Build info: version: '2.37.0', revision: 'a7c61cbd68657e133ae96672cf995890bad2ee42', time: '2013-10-18 09:51:02'
Upvotes: 1
Views: 22242
Reputation: 31
Your "contains" function has no closing bracket and needs the right quoting.
If CHECKBOX and TEMPLATE are Strings, try this:
driver.findElement(By.xpath("//input[@type='checkbox']/following-sibling:://td[contains(text(),'template')]"))
if they are variables, try this:
driver.findElement(By.xpath("//input[@type='" +checkbox+"']/following-sibling:://td[contains(text(),'"+template+"')]"))
Upvotes: 2
Reputation: 113
"//input[@type="+"checkbox"+"]/following-sibling:://td[contains(text(),"+"template"+"]"
produces a wrong string. Try from python:
"//input[@type="+"checkbox"+"]/following-sibling:://td[contains(text(),"+"template"+"]"
'//input[@type=checkbox]/following-sibling:://td[contains(text(),template]'
You should surround checkbox and template with quotes to get
"//input[@type="checkbox"]/following-sibling:://td[contains(text(),"template"]"
or
"//input[@type='checkbox']/following-sibling:://td[contains(text(),'template']"
use
"//input[@type="+"'checkbox'"+"]/following-sibling:://td[contains(text(),"+"'template'"+"]"
or
"//input[@type='{type}']/following-sibling:://td[contains(text(),'{text}']".format(type='checkbox',text='template')
Upvotes: 0
Reputation: 32895
Looks like your messed up with quotes. Use single quotes in XPath to avoid issues like this.
// if template is the text within your XPath
driver.findElement(By.xpath("//input[@type='checkbox']/following-sibling:://td[contains(text(), 'template']"));
// if template is your variable, then it should be
driver.findElement(By.xpath("//input[@type='checkbox']/following-sibling:://td[contains(text(), " + template + "']"));
Also, please read the error carefully, it tells enough information you need already. As you can see, there are no quotes in the selector in the message.
The given selector //input[@type=checkbox]/following-sibling:://td[contains(text(),template] is either invalid or does not result in a WebElement.
Upvotes: 5