- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6683 Articles for Javascript
16K+ Views
Showing and hiding elements is a common task in JavaScript. It can be used to create dynamic user interfaces, where the content changes depending on the user's input or interaction with the page. One way of doing this is to show a hidden div when a select option is selected. This article will guide you through how to do this using JavaScript. A Boolean attribute is the one that was chosen. It indicates that a choice should be preselected when the page loads if it is present. In the drop-down list, the pre-selected option will be shown first. To ... Read More
7K+ Views
When a user changes the value of an element, the , , and elements fire the change event. The change event does not always fire for every change to an element's value, unlike the input event. Instead, use querySelector() along with addEventListener(). Let’s discuss one by one to understand how they will work. The addEventListener() Method − The addEventListener() is a method used to register an event handler for the specified event type on the current element. It allows you to specify a function that will be called whenever the specified event occurs on the element. Following ... Read More
5K+ Views
Creating radio buttons dynamically using an array in JavaScript is a useful way to provide users with multiple options for input. When the user clicks on one of the radio buttons, it will be selected and any other choices will be deselected automatically. This process can be automated by looping through an array that contains all the possible values and creating a new radio button element for each item in the array. To dynamically create radio button using an array, use the concept of createElement() and appendChild().Let’s look at the concept to understand more about dynamically creating a radio buttons. ... Read More
522 Views
We can click a link with the webdriver click and Javascript click. For the Selenium webdriver click of a link we can use link text and partial link text locator. We can use the methods driver.findElement(By.linkText()) and driver.findElement(By.partialLinkText()) to click.The links in an html code are enclosed in an anchor tag. The link text enclosed within the anchor tag is passed as argument to the driver.findElement(By.linkText()) method. The partial matching link text enclosed within the anchor tag is passed as argument to the driver.findElement(By.partialLinkText()) method. Finally to click on the link the click method is used.Let us see the html ... Read More
2K+ Views
We can read Javascript variables with Selenium webdriver. Selenium can run Javascript commands with the help of executeScript method. The Javascript command to be executed is passed as an argument to the method. Also we have to add the statement import org.openqa.selenium.JavascriptExecutor to work with Javascript.SyntaxJavascriptExecutor j = (JavascriptExecutor) driver; j.executeScript("return document.title")Let us obtain the browser title of the below page by reading the value from Javascript variable. The output should be About Careers at Tutorials Point – Tutorialspoint.ExampleCode Implementationimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.JavascriptExecutor; public class JavascriptReadValue{ public static void main(String[] args) { ... Read More
622 Views
We can run Javascript in Selenium webdriver with Python. The Document Object Model communicates with the elements on the page with the help of Javascript. Selenium executes the Javascript commands by taking the help of the execute_script method. The commands to be executed are passed as arguments to the method.Some operations like scrolling down in a page cannot be performed by Selenium methods directly. This is achieved with the help of Javascript Executor. The window.scrollTo method is used to perform scrolling operation. The pixels to be scrolled horizontally along x axis and pixels to be scrolled vertically along y axis ... Read More
3K+ Views
We can get the return value of Javascript code with Selenium webdriver. Selenium can run Javascript commands with the help of executeScript method. The Javascript command to be executed is passed as an argument to the method.We shall be returning the value from the Javascript code with the help of the keyword return. Also we have to add the statement import org.openqa.selenium.JavascriptExecutor to work with Javascript.SyntaxJavascriptExecutor j = (JavascriptExecutor) driver; j.executeScript("return document.getElementsByName('txtSearchText')[0].value")Let us obtain the value entered in the edit box. The output should be Selenium.ExampleCode Implementationimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.JavascriptExecutor; public class ... Read More
10K+ Views
The task is to match a specific word or character which is in regex with a string. The regex (regular expressions) is a pattern that is used to match character combinations in strings. Here we include the test(), match(), and matchAll() methods to match the following word in regex. We have some boundary-type assertions, in which we have used \b. Consider a sentence – “mickey is holding mic.” Using regex - \bmic\b will match the word mic but not the word mic in mickey. It is a word boundary. Another assertion is (g), It is a global search flag. Consider ... Read More
1K+ Views
Extract the value and convert it from String to integer to get price value from span tag.ExampleFollowing is the code − Document Value= 10 $(document).ready(function () { var v = parseInt($(".purchase.amount") .text() .trim() .replace(', ', '')); var totalValue = v * 10; console.log(totalValue); ... Read More
60 Views
To remove listener from outer function, use removeEventListener().ExampleFollowing is the code − Document Press Me var demoId = document.getElementById('demo'); demoId.addEventListener('click', function fun() { outerFunction(this, fun); }, false); function outerFunction(self, funct) { console.log('outer function is called....'); self.removeEventListener('click', funct, false); console.log("Listener has been removed...") } To run the above program, save the file name anyName.html(index.html) and right click on the file. Select the option “Open with live server” in VS Code editor.OutputThis will ... Read More