Stop setInterval After Time or Actions in JavaScript

AmitDiwan
Updated on 26-Oct-2020 11:06:41

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 −

Sort an Array of Integers Correctly in JavaScript

AmitDiwan
Updated on 26-Oct-2020 11:04:21

392 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 ]

Get Values of Selected Checkboxes using jQuery

AmitDiwan
Updated on 26-Oct-2020 10:56:01

452 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

Simulate Pressing Enter in HTML Text Input with Selenium

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:33:51

785 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

Change Focus to a New Popup Tab in Selenium

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:32:15

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

Wait Until an Element No Longer Exists in Selenium

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:30:40

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
Updated on 26-Oct-2020 07:28:38

443 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

Get HTML Source of WebElement in Selenium WebDriver Using Python

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:27:13

13K+ Views

We can get html source of a webelement with Selenium webdriver.We can get the innerHTML attribute to get the source of the web element.The innerHTML is an attribute of a webelement which is equal to the text that is present between the starting and ending tag. The get_attribute method is used for this and innerHTML is passed as an argument to the method.Syntaxs = element.get_attribute('innerHTML')We can obtain the html source of the webelement with the help of Javascript Executor. We shall utilize the execute_script method and pass arguments index.innerHTML and webelement whose html source is to be retrieved to the ... Read More

Click on Hidden Element Using Selenium WebDriver

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:24:25

9K+ 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

Navigate Back to Current Page from Frame in Selenium WebDriver

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:21:49

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

Advertisements