Below error is shown:
invalid selector: Unable to locate an element with the xpath expression //*[#id='center_column]'/div[1] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[#id='center_column]'/div[1]' is not a valid XPath expression.
Code trial:
driver.findElement(By.xpath("//*[#id='center_column]'/div[1]")).getCssValue("background-color")
As #Guy has pointed out you have a SyntaxError the XPath's id is a string within the locator hens the '' now your XPath should look something like:
By.xpath("//*[#id='center_column']/div[1]")
Not
By.xpath("//*[#id='center_column]'/div[1]")
Related
If key value length is 11808 Unable to update session storage key value using selenium automation
Small length key values are setting but long length key values getting JS error
Manually it is working but using selenium automation getting JS error.
setItemInsessionStorage method using:
java.lang.AssertionError: org.openqa.selenium.JavascriptException: javascript error: missing ) after argument list
This error message...
java.lang.AssertionError: org.openqa.selenium.JavascriptException: javascript error: missing ) after argument list
...implies that there is a syntax error within the Javascript line of code.
A bit of more information about your usecase interms of your code block would have helped us to analyze the error in a better way. However in majority of the cases, this error is observed in the following cases:
Incase the " marks are not escaped properly. As an example:
onclick="(canLaunch('" + v.LibraryItemId + " '))"
^ escape character is missing
Ideally, the line should be:
onclick=\"(canLaunch('" + v.LibraryItemId + " '))\"
Incase the function() passed are not closed properly. As an example:
$(document).ready(function(){
}
Ideally, the line should be:
$(document).ready(function(){
});
I am using the following code for POM :
#FindBy(xpath="[#value='Send query']") private WebElement queryButton;
I am getting this error
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression [#value='Send query'] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '[#value='Send query']' is not a valid XPath expression.
The error "invalid selector" is pretty explanatory: [#value='Send query'] is not a valid XPath.
You probably meant //*[#value='Send query'].
Can anyone please tell me, if there is any mistake with my xpath. I have made it dynamic, to accept values from the parameter passed.
Xpath used in my code as :
wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//div[#id='categories_block_left']/div[1]/ul[1]/li/a[contains(text(),'"+subCategory+"')]/Preceding-sibling::span[1]")));
Xpath I am getting on run time in the console after execution:
//div[#id='categories_block_left']/div[1]/ul[1]/li/a[contains(text(),'Tops')]/Preceding-sibling::span[1]
If I try to inspect above(runtime) by mentioning xpath in Firpath console, it is getting detected. But selenium is not able to detect this element.
Here is page URL:
http://automationpractice.com/index.php?id_category=3&controller=category
In the eclipse console I am getting error as :
Expected condition failed: waiting for presence of any elements located by By.xpath: //div[#id='categories_block_left']/div[1]/ul[1]/li/a[contains(text(),'Tops')]/Preceding-sibling::span[1]
SyntaxError: Failed to execute 'evaluate' on 'Document':
JavascriptExecutor jse = (JavascriptExecutor)driver;
WebElement element = driver.findElement(By.xpath(".//*[#id='reviewMetadata']/a']"));
jse.executeScript("arguments [0],click();",element);
Error: Exception in thread "main"
org.openqa.selenium.InvalidSelectorException: The given selector
.//[#id='reviewMetadata']/a'] is either invalid or does not result in
a WebElement. The following error occurred: InvalidSelectorError:
Unable to locate an element with the xpath expression
.//[#id='reviewMetadata']/a'] because of the following error:
SyntaxError: The expression is not a legal expression.
You use extra quote after a element. You should use
".//*[#id='reviewMetadata']/a]"
Also replace comma with dot and remove space in
"arguments [0],click();"
to prevent following issues
JavascriptExecutor jse = (JavascriptExecutor)driver;
WebElement element = driver.findElement(By.xpath("//*[#id='reviewMetadata']/a]"));
jse.executeScript("arguments [0],click();",element);
Try replacing these lines and run. I guess you copied that xpath from FirePath. Don't forget to delete the full stop which is in the start of the xpath.
I'm using Cucumber with Watir Web-driver and Chrome browser.
When I execute my tests, sometimes there is an error like this:
"Selenium::WebDriver::Error::InvalidSelectorError: invalid selector: Unable to locate an element with the xpath expression //a[contains(., 'Joao Moreira')] because of the following error:
TypeError: Failed to execute 'createNSResolver' on 'Document': parameter 1 is not of type 'Node'.
(Session info: chrome=43.0.2357.81)
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64)"
I tried to get an answer trough Google but with no success.
Pretty sure this is this issue here: https://code.google.com/p/selenium/issues/detail?id=8600
And it is fixed as of Selenium 2.46.0. I haven't seen the error since moving.
Add a line to handle the exception thrown. Seems like the error halts the test. This has nothing to do with the locator, or iframe.Try to wrap your method in rescue clause:
begin
{your method}
rescue
Selenium::WebDriver::Error::InvalidSelectorError
end