org.openqa.selenium.JavascriptException: javascript error: missing ) after argument list error when updating session storage key value using Selenium - 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(){
});

Related

Selenium IDE - what is causing this error message ("Cannot read property 'trim' of undefined") [duplicate]

This question already has answers here:
An error has occured in 'site url': Uncaught TypeError: Cannot read property 'getColomnSet' of undefined with Selenium and Python
(2 answers)
"unknown error: cannot read property 'scrollleft' of null" in Chrome using selenium
(1 answer)
Closed 2 years ago.
I am trying to read in a count from a webpage screen with Selenium IDE using the following code. The count increments automatically on-screen.
I am encountering an error message and I'm not sure how to resolve it - I suspect I may need to define the variable but I have been unable to figure how to do it.
store value id=eas-collection-notification x
echo ${x}
storeValue on id=eas-collection-notification with value x Failed:
Cannot read property 'trim' of undefined
Can you please advise me how to make this code work? I just want to compare the number on-screen to take a further action once it reaches a defined threshold.
Thank you.

The selector "ng-component" did not match any elements running Angular 8 example

I am working on the following example:
Example
I am getting a run-time error:
Error: The selector "ng-component" did not match any elements
Any idea why?
Thanks

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

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

Is there anyway to capture selenium test failed message like a timeoutexpection in TestContext?

I have code to capture screenshot on test failure. What I'm doing right now is naming the screenshot with "TestContext.CurrentContext.Test.ID + "_"+ TestContext.CurrentContext.Test.Name". I want to add test failed message to it something like "Message: OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"css selector","selector":".applicationTitleSteps"}". Is there anyway to do this?
You can get read the Exception message as string by simply casting your Exception object. Perform string manipulation options like splitting to get the required value and concatenate with your current name, which you are giving for the screenshot while saving.
Your exception catching code should be like this, catch(exception ex).

protractor ExpectedConditions.textToBePresentInElement returns false when the expected message has mora than one line

I'm facing a new problem with protractor ,
When I try to use this selenium method:
ExpectedConditions.textToBePresentInElement
It is returning false because my element returns this messsage:
Connection Unavailable.
Could not connect to the equipment at this time
This is my expected string:
message : Connection Unavailable.\nCould not connect to equipment at this time
then my method call is:
browser.wait(ExpectedConditions.textToBePresentInElement(element, message), 160000, 'The expected text is not present in the UI');
Maybe somebody can help me with it
Maybe it's not the best approach, but it'll solve your problem. Simply replace your expected messages with ones that have no \n:
browser.wait(ExpectedConditions.textToBePresentInElement(element, message.replaceAll("\\n", " ")),
160000, 'The expected text is not present in the UI');