Articles on Trending Technologies

Technical articles with clear explanations and examples

How to make a setInterval() stop after some time or after a number of actions in JavaScript?

AmitDiwan
AmitDiwan
Updated on 26-Oct-2020 2K+ Views

Use some conditions to stop after some time.The below code will stop in half a minute.ExampleFollowing is the code −            Document    var now = new Date().getTime();    var interval = setInterval(function () {       if (new Date().getTime() - now > 30000) {          clearInterval(interval);          return;       }       console.log("working");    }, 2000); 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 produce the following output −

Read More

How to sort an array of integers correctly in JavaScript?

AmitDiwan
AmitDiwan
Updated on 26-Oct-2020 407 Views

To sort an array of integers, use sort() in JavaScript.ExampleFollowing is the code −var arrayOfIntegers = [67, 45, 98, 52]; arrayOfIntegers.sort(function (first, second) {    return first - second; }); console.log(arrayOfIntegers);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo310.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo310.js [ 45, 52, 67, 98 ]

Read More

Use jQuery to get values of selected checkboxes?

AmitDiwan
AmitDiwan
Updated on 26-Oct-2020 492 Views

Yes, we can use jQuery to get values of selected checkboxes using the concept of input. We have to also use the :checked selector.ExampleFollowing is the code −            Document        Cricket        Listening Music Reading NewsPaper Click Me    $(document).ready(function () {       $("button").click(function () {          $('input[name="checkDemo"]:checked').each(function () {             console.log(this.value);          });       });    }); To run the above program, save the ...

Read More

How to simulate pressing enter in html text input with Selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 829 Views

We can simulate pressing enter in the html text input box with Selenium webdriver. We shall take the help of sendKeys method and pass Keys.ENTER as an argument to the method. Besides, we can pass Keys.RETURN as an argument to the method to perform the same task.Also, we have to import org.openqa.selenium.Keys package to the code for using the Keys class. Let us press ENTER/RETURN after entering some text inside the below input box.ExampleCode Implementation with Keys.ENTER.import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.By; import org.openqa.selenium.Keys; public class PressEnter{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", ...

Read More

How do I change focus to a new popup tab in Selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 4K+ Views

We can change focus to a new popup tab with Selenium webdriver. The getWindowHandles and getWindowHandle methods are available to handle new popup tabs. The getWindowHandles method stores all the currently opened window handles in Set data structure.The getWindowHandle method stores the window handle of the opened browser in focus. The iterator method is used to iterate over all the window handle ids. We have to add import java.util.Set to accommodate Set and import java.util.List and import java.util.Iterator statements to accommodate the iterator in our code.Selenium driver object can access the elements of the parent window. In order to switch ...

Read More

How to wait until an element no longer exists in Selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 8K+ Views

We can wait until an element no longer exists in Selenium webdriver. This can be achieved with synchronization in Selenium. We shall add an explicit wait criteria where we shall stop or wait till the element no longer exists.Timeout exception is thrown once the explicit wait time has elapsed and the expected behavior of the element is still not available on the page. To check if an element no longer exists on the page, we can take the help of the expected condition invisibilityOfElementLocated.To implement explicit wait conditions, we have to take help of the WebDriverWait and ExpectedCondition class.ExampleCode Implementation.import ...

Read More

Selenium Web Test Automation Framework Best Practices.

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 471 Views

The best practices for Selenium web test automation framework are listed below −Use of dynamic waits like implicit wait and explicit wait instead of using Thread.sleep in the framework to handle sync issues in the application.Usage of Page Object Model framework design to segregate the test scripts from the locators. In case of changes in the webelement properties, test scripts need not be modified only the locators undergo change.Usage of Behavior Driven Development framework. This allows the participation of all members in the agile team to participate in product development.Encourage testing to start from very early phases and in regular ...

Read More

How do you click on an element which is hidden using Selenium WebDriver?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 10K+ Views

We can click on an element which is hidden with Selenium webdriver. The hidden elements are the ones which are present in the DOM but not visible on the page. Mostly the hidden elements are defined by the CSS property style="display:none;". In case an element is a part of the form tag, it can be hidden by setting the attribute type to the value hidden.Selenium by default cannot handle hidden elements and throws ElementNotVisibleException while working with them. Javascript Executor is used to handle hidden elements on the page. Selenium runs the Javascript commands with the executeScript method. The commands ...

Read More

How to navigate back to current page from Frame in selenium webdriver?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 2K+ Views

We can navigate back to the current page from frame with Selenium webdriver. A frame is defined with , or tag in html code. A frame is used to embed an HTML document within another HTML document.Selenium by default has access to the main browser driver. In order to access a frame element, the driver focus has to shift from the main browser window to the frame. To again focus back to the current page from frame, the method switchTo().defaultContent() is used.ExampleCode Implementation.import 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; public class SwitchBackFrame{    public static ...

Read More

How to use regex in selenium locators?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 8K+ Views

We can use regex in locators in Selenium webdriver. This can be achieved while we identify elements with the help of xpath or css locator. Let us have a look at the class of an element in its html code. The class attribute value is gsc-input.Here, with the css expression, we can use the * and perform a partial match with the class attribute value. The css value shall be input[class*='input']. This means the subtext input is present in the actual text gsc-input. We can also use the ^ and perform a match with the class. The css value shall ...

Read More
Showing 37061–37070 of 61,248 articles
Advertisements