Retrieving a 4-digit number from a text string using Selenium IDE - encountering an error notification

I'm currently working on creating a regex in Selenium IDE to extract a 4-digit number from an input text that has been stored using the storeValue command. An example of the string that is stored is:

'undergraduate 2016 computer science'
. When successfully extracting the 4-digit number, the result should be 2016, then reassigned and stored as a variable named year. Here is my attempt at achieving this:

storeValue | xpath=/html/body/form/div[4]/div/div/section/div[1]/div/input[1] | year
storeEval | storedVars['year'].match(/\\d{4}/)[0]; | year

However, upon running the code, I encountered the error message:

[error] Threw an exception: missing ; before statement
. Does anyone have suggestions on how this issue can be resolved? Thank you in advance.

Answer №1

In order to use the regex properly, enclose it within the necessary js regex delimiters /regex/ and then place it inside braces.

Make sure to include storedVars['year'].match(/[0-9]{4}/);

If you want to specifically match a 4-digit number, remember to add word boundaries.

storedVars['year'].match(/\b[0-9]{4}\b/); 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing jQuery to Parse XML for an XMLHttpRequest

Upon receiving the response below, I am trying to extract the value of sessiontoken, which is -4611685691785827288. <com.abc.csm.common.LoginResponse> <sessiontoken>-4611685691785827288</sessiontoken> <isSuccess>true</isSuccess& ...

I'm attempting to create a text toggle button for displaying more or less content

I am currently working on implementing a show more/show less button feature. However, the current version is not very effective as I only used slicing to hide content when the state is false and display it all when true. Now, my goal is to only show the ...

encountering the following exception while running java and selenium code

Encountering a null pointer exception while running the code, despite verifying the locator multiple times, Tried several attempts but received the same response, POM class created for login POM class created for home page Test class for creating pet ## ...

What is the most effective method to determine if a given string is suitable for $compile in Angular?

I am currently in the process of creating a directive that is designed to accept a "message" input which may contain HTML and nested Angular directives. In my directive's controller, I am using the following code: var compiled = $compile(message)($sc ...

Displaying outcomes solely based on JSON upon choosing a filter

Goal I aim to only show results once their respective state is chosen. Currently, all results are displayed automatically upon page load. I prefer if nothing is shown initially. Only when a state is selected should the corresponding results appear. Bac ...

Tips for running Scrapy and Selenium on a webpage that utilizes angular JavaScript to serve data

I have been working on a web scraper that follows this process: Visit site A -> click on the buy now button -> redirected to Amazon -> scrape data -> return to site A The issue I am facing is that the site is built using AngularJS, and I am h ...

The Yeoman/Grunt-usemin is failing to update the index.html file even after adding new JavaScript code

As I work on developing a web app using Yeoman and the Angular generator on Windows 7, I go through the process of running 'yo angular' followed by 'grunt' to build the app for deployment. The index.html file in the dist folder gets upd ...

Issues with JQuery Ajax rendering in browser (suspected)

I'm encountering an issue on my webpage. I have a div with two hidden fields containing values of 0 and 2, respectively. Upon clicking a button that triggers an AJAX query, the div contents are updated with hidden field values of 1 and 2. However, it ...

JavaScript's toFixed method for decimals

I am encountering an issue with displaying prices for my products. I have labels in the form of "span" elements with prices such as 0.9, 1.23, and 9.0. I am using the method "toFixed(2)" to round these prices to two decimal places. However, I have notice ...

Python Techniques for Scraping Dynamic Webpages

I am attempting to extract data from this specific website using Python. When inputting the company code (e.g., 6177), the URL remains the same but the content on the page changes. There is only one cell that requires extraction. Attached is a screenshot ...

Bootstrap: enabling the opening of a modal without triggering the collapse feature on the parent element

Here's a simple scenario: I have a Bootstrap 4 table with rows that I would like to be clickable to expand additional hidden rows. The entire tr has data-toggle="collapse". However, within that TR, there are some buttons that I want to open ...

Ajax requests function properly only on one occasion

My select option works perfectly the first time, but then the request does not execute again. I suspect that the issue lies with the 'onchange' event. Here is my Ajax code : jQuery(document).ready(function($) { $('#referenceProduit') ...

Despite installing Google Chrome and the Chrome WebDriver on Ubuntu, the code `driver = webdriver.Chrome('/usr/bin/chromedriver')` still does not work as expected

I recently started using Ubuntu as my operating system and successfully installed Google Chrome along with the Linux Chrome driver. After importing necessary libraries for Selenium automation, I encountered an issue when trying to run the code: driver = w ...

Utilizing React's useState to store data in local storage

I am trying to figure out how to save data from a photos database API into local storage using the useState hook in React. Despite my attempts, I have not been successful with the useState method as the data in local storage gets cleared upon page refres ...

Edit HTML and CSS in live mode while also running JavaScript for instant enhancement

Recently, I created a script that allows me to build a web page in real-time. I can input HTML and CSS codes without any issues, but unfortunately, I am unable to execute JavaScript due to the limitations of the string-based editor I am using. Can anyone o ...

Using JavaScript to Set Values and Manage Session State in APEX

Trying to utilize JavaScript in Oracle APEX to set the value and session state. See below function that is being called: function updateItemValue(element) { $s('P2020_SELECTED', element); apex.server.process ('MY_PROCESS', { ...

Regular expressions can be used to identify words in all capital letters within a sequence, while still permitting certain connecting words like "and

Imagine a scenario where you have a string like this: Hello There what have You Been Doing. I am Feeling Pretty Good and I Want to Keep Smiling. The desired result is: ['Hello There', 'You Been Doing', 'I am Feeling Pretty Good ...

AngularJS is throwing a TypeError because it cannot access the '0' property of an undefined value

for ( var i = 0; i < members.length; i++ ) { var value = value[i]; console.log(value); } Feeling really bewildered by how this could be incorrect... 'i' is set to zero, so it's perplexing how the value couldn' ...

The function driver.switchTo.frame() does not exist

I am a beginner with Selenium and facing an issue with a task I need to accomplish: Go to https://pastebin.com Paste "Hello from WebDriver" Set the paste expiration to 10 Minutes //Struggling with this step Set the paste title as "helloweb" I am using Ja ...

Opencart is displaying a resource as a font even though it was transferred with a MIME type of text/html

Despite searching extensively on Stack Overflow, none of the answers I found have been able to resolve my issue. I am using an Opencart Store with custom typography and encountering the following error: Resource interpreted as Font but transferred with MI ...