SyntaxError: Failed to execute 'evaluate' on 'Document': - selenium

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':

Related

org.openqa.selenium.JavascriptException: javascript error: missing ) after argument list error when updating session storage key value using Selenium

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(){
});

getting error while trying to work with xpath

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]")

selenium POM web driver in java error

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'].

TypeError: Failed to execute 'createNSResolver' on 'Document': parameter 1 is not of type 'Node'

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

Parse.FacebookUtils.init gives InvalidCharacterError

I'm getting Uncaught InvalidCharacterError: Failed to execute 'createElement' on 'Document': The tag name provided ('<iframe name="fb_xdm_frame_http"/>') is not a valid name. when I try to run Parse.FacebookUtils.init. Init code can be found at https://gist.github.com/ryansmith94/0ff03caf002fa2a8eb8b. Any ideas how I can resolve this problem?
Fixed this by changing Facebook's sdk.js code at line 46. https://developers.facebook.com/bugs/1466190186951391