Javascript Articles

Page 473 of 534

How to identify the nth sub element using xpath?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 10-Jun-2020 7K+ Views

We can identify the nth sub element using xpath in the following ways −By adding square brackets with index.By using position () method in xpath.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class SubElement {    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/index.htm";       driver.get(url);       driver.manage().window().maximize();       driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);       // xpath using position() targeting the first element with type text       driver.findElement(By.xpath("//input[@type='text'][position()=1]"))     ...

Read More

Among id, name, xpath and css, which locator should be used?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 10-Jun-2020 427 Views

Each of the locators has some significance. If the page contains uniqueattribute values, we should use them first. However if there are no unique elements, we should use css selector as it is more effective in terms of speed.Css also has a drawback that we cannot traverse from child to parent node which means we cannot travel backward. But xpath allows this feature. Xpath is the most common locator in Selenium and performs traversal through DOM elements and attributes to identify an object.An xpath is represented by two ways namely ‘/ ‘and ‘// ‘. A forward single slash means absolute ...

Read More

How to get the value of the edit box in Selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 10-Jun-2020 636 Views

We can get the value of the edit box in Selenium by the following ways −By using getText () method.Using the class JavascriptExecutor.Code Implementation with method getText ().Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class GetValueScripting {    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/index.htm";       driver.get(url);       driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);       String text = driver.findElement(By.className("gsc-input")).getText();       System.out.println("Extracted text is " + text);       driver.close();   ...

Read More

HTML5 Input type “number” in Firefox

karthikeya Boyini
karthikeya Boyini
Updated on 04-Jun-2020 961 Views

The min attribute of the input type number isn’t supported by Firefox, but it works correctly in Google Chrome.ExampleLet us see an example −           HTML input number                        Mention any number between 1 to 10                              

Read More

Create JS Radial gradient with matrix in HTML

Sreemaha
Sreemaha
Updated on 02-Jun-2020 305 Views

JSRadial gradient with matrix is created in the following way. You can try to run the following way to create JS Radial gradient with matrix −var canvas1 = document.getElementById("canvas"); //canvas1 variable to identify given canvas var ctx1 = canvas.getContext("2d"); //This is used to tell context is 2D   var gradient1 = ctx1.createRadialGradient(100/horizontalScale, 100/verticalScale, 100, 100/horizontalScale, 100/verticalScale, 0); //This will create gradient with given canvas context   gradient1.addColorStop(1, "green"); //New color green is added to gradient gradient1.addColorStop(0, "red"); //New color red is added to gradient ctx1.scale(horizontalScale, verticalScale); //Context matrix ctx1 is shrinked according to horizaontal and vertical scale ...

Read More

How to set all the background properties in one declaration with JavaScript DOM?

Swarali Sree
Swarali Sree
Updated on 23-May-2020 159 Views

To set the background in JavaScript, use the background property. It allows you to set the background color, image, position, etc.ExampleYou can try to run the following code to learn how to set all the background properties in a single declaration with JavaScript.Live Demo           Click to Set background                function display() {             document.body.style.background = "url('https://www.tutorialspoint.com/html5/images/html5-mini-logo.jpg') repeat right top";          }          

Read More

How to search and display the pathname part of the href attribute of an area with JavaScript?

Vrundesha Joshi
Vrundesha Joshi
Updated on 23-May-2020 181 Views

To get the pathname part of the href attribute of an area in JavaScript, use the pathname property.ExampleYou can try to run the following code to display the pathname part.                                                var x = document.getElementById("myarea").pathname;          document.write("Pathname: "+x);          

Read More

How to search the alternate text of an image-map area in JavaScript?

Sravani S
Sravani S
Updated on 23-May-2020 193 Views

To search the alternate (alt) text of an image-map area in JavaScript, use the alt property. You can try to run the following code to get the alternate text.Example                                                      var x = document.getElementById("myarea").alt;          document.write("Alternate Text: "+x);          

Read More

How to search the value of the type attribute of a link in JavaScript?

Jennifer Nicholas
Jennifer Nicholas
Updated on 23-May-2020 240 Views

To search the value of the type attribute of a link in JavaScript, use the type property. You can try to run the following code to get the value of type attribute.Example           Qries                var x = document.getElementById("qriesid").type;          document.write("Value of the type attribute: "+x);          

Read More

What will happen when { } is converted to String in JavaScript?

Arushi
Arushi
Updated on 23-May-2020 173 Views

Use the String() method in JavaScript to convert to String. You can try to run the following code to learn how to convert { } to String in JavaScript.ExampleLive Demo           Convert {} to String                var myVal = {};          document.write("String: " + String(myVal));          

Read More
Showing 4721–4730 of 5,338 articles
« Prev 1 471 472 473 474 475 534 Next »
Advertisements