Reputation: 101
Please see below attached the relevant XML code and my java code to locate the element:
Java code:
//Set date range
WebElement parentStartdate = obj.findElement(By.xpath("//[@id=typein_[Parameters].[Parameter 3]]"));
WebElement child=parentStartdate.findElement(By.xpath("//input[@value='1/1/2019']"));
I get the follow error: Exception in thread "main" org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //[@id=typein_[Parameters].[Parameter 3]] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//[@id=typein_[Parameters].[Parameter 3]]' is not a valid XPath expression.
Any help appreciated!
Upvotes: 1
Views: 124
Reputation: 503
Try this selector:
//div[contains(@class, 'TypeInDiv')]/span[@class="TypeInQuerySpan"]/input[@type='text'][@class='QueryBox'][@value='1/1/2019']
the 3 identifiers on input are not mandatory, you can choose 1 or 2 or leave all 3, you decide.
Upvotes: 1
Reputation: 4507
If you have only one QueryBox on the webpage then you can select the element by using the following xpath for your case:
WebElement element = driver.findElement(By.xpath("//input[@class='QueryBox']"));
Upvotes: 1
Reputation: 8394
As the error message says, that is not a valid Xpath expression. Select the first element by
WebElement parentStartdate = obj.findElement(By.xpath("//span[@class='TypeInQuerySpan']/input"));
Upvotes: 1