Rearranging Array Elements in JavaScript

AmitDiwan
Updated on 07-Apr-2021 07:57:44

221 Views

ProblemJavaScript function that takes in an array of literals, arr, as the first and the only argument. This array contains some duplicates placed adjacently.Our function should rearrange the elements of the array such that no two elements in the array are equal. Our function should return the rearranged array, given that it's guaranteed that there exists at least one possible way of such arrangement.For example, if the input to the function is −const arr = [7, 7, 7, 8, 8, 8];Then the output should be −const output = [7, 8, 7, 8, 7, 8];Output Explanation:There may be other correct possible ... Read More

Finding Sequential Digit Numbers Within a Range in JavaScript

AmitDiwan
Updated on 07-Apr-2021 07:49:20

430 Views

Sequential Digits NumberA number has sequential digits if and only if each digit in the number is one more than the previous digit.ProblemWe are required to write a JavaScript function that takes in an array, arr, of exactly two elements specifying a range.Our function should return a sorted array of all the integers in the range arr (limits inclusive) that have sequential digits.For example, if the input to the function is −const arr = [1000, 13000];Then the output should be −const output = [1234, 2345, 3456, 4567, 5678, 6789, 12345];ExampleThe code for this will be − Live Democonst arr = [1000, ... Read More

Distributing Bananas Problem in JavaScript

AmitDiwan
Updated on 07-Apr-2021 07:47:11

396 Views

ProblemSuppose there are n people standing in a queue, we wish to distribute bananas to the people in the following way −We give 1 banana to the first person, 2 bananas to the second person, and so on until we give n bananas to the last person.Then, we go back to the start of the row, giving n + 1 bananas to the first person, n + 2 bananas to the second person, and so on until we give 2 * n bananas to the last person.This process repeats (with us giving one more banana each time, and moving to ... Read More

Path with Smallest Sum in JavaScript

AmitDiwan
Updated on 07-Apr-2021 07:26:18

328 Views

ProblemJavaScript function that takes in a 2-D array of numbers as the first and the only argument.Our function should find paths from the 2-D array by picking exactly one element from each row, and no two elements picked from adjacent rows should be in the same column. Out of all these paths, our function should return the sum of that path that has the minimum sum.For example, if the input to the function is −const arr = [    [4, 7, 1],    [2, 8, 3],    [5, 6, 9] ]Then the output should be −const output = 9;Output ExplanationBecause ... Read More

Alternative of Click in Selenium

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:58:14

6K+ Views

There are several alternatives to the usage of click method in Selenium webdriver. We can use the JavaScript Executor to perform a click action. Selenium can execute JavaScript commands with the help of the executeScript method.The parameters – arguments[0].click() and locator of the element on which the click is to be performed are passed to this method.SyntaxWebElement n=driver.findElement(By.linkText("Refund")); JavascriptExecutor j = (JavascriptExecutor) driver; j.executeScript("arguments[0].click();", n);Exampleimport 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 JsClickLink{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); ... Read More

Google Search Automation with Python Selenium

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:57:39

7K+ Views

We can perform Google search automation with Selenium webdriver in Python. First of all, we shall locate the Google search box with the help of any of the locators like id, css, xpath, class, or name.Then simulate the action of pressing the ENTER key with the help of Keys.ENTER/Keys.RETURN. To perform this operation, we have to use the method send_keys and then pass the parameter – Keys.RETURN /Keys.ENTER. Also, we have to add the statement - from selenium.webdriver.common.keys import Keys to use the Keys class.Examplefrom selenium import webdriver from selenium.webdriver.common.keys import Keys import time #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") ... Read More

What is Following Sibling in Selenium

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:57:08

26K+ Views

We can use the concept of following-sibling in xpath for identifying elements in Selenium. It identifies the siblings of the context node. The siblings should be located at the equal level of the existing node and should have the same parent.Let us see an example of an element with ul tag having more than one child with li tag. Then let us try to locate the fifth li element (Effective Resume Writing) from the first li element with class attribute sreading.Syntax//li[@class='sreading']/following-sibling::li[4]Here, we are locating the fifth child of ul tag, but we have provided li[4] since we are locating the ... Read More

Handle SSL Certificate in Firefox using Selenium WebDriver

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:56:33

1K+ Views

We can handle SSL certificate in Firefox with the help of the Selenium webdriver by using the FirefoxProfile class. Then setting the parametersetAcceptUntrustedCertificates to true. A SSL is a protocol followed to create a secure connection between the client (browser) and the server.SSL checks the authenticity of a website and encodes the visitors while they send or get information from the site. Some of the advantages of SSL certificates are −Earns the users trust by increasing the business growth.Provides a secure gateway for online payment by securing the customer data like username, password, and other banking information.Keeps away from hacker ... Read More

Handle SSL Certificate Error Using Selenium WebDriver

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:56:05

1K+ Views

We can handle SSL certificate error using Selenium webdriver while we try to launch a web page based on HTTP. SSL certificate errors are encountered in multiple browsers like Chrome, Safari, and Firefox and so on.SSL certificate error comes up if the site we are making an attempt to access has an outdated, invalid or an untrusted certificate. SSL or Secure Sockets Layer is a protocol followed to create a connection between the client (browser) and the server.To handle the SSL certificate error we have to use the DesiredCapabilities class and then accept the SSL error by setting the ACCEPT_SSL_CERTS ... Read More

Scroll Down in a Webpage Using Selenium WebDriver in Python

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:49:19

3K+ Views

Yes it is possible to scroll down in a webpage using Selenium webdriver in Python by using the JavaScript Executor. Selenium can execute JavaScript commands with the help of execute_script method.The JavaScript command to be used is passed as a parameter to this method. Also, it must be noted that scrolling actions cannot be performed directly with any methods in Selenium.To scroll down in a page to the end, we have to pass the command window.scrollTo as a parameter to the execute_script method. Also, the values 0 and document.body.scrollHeight are passed as parameters to the window.scrollTo command.Syntaxdriver.execute_script("window.scrollTo(0, document.body.scrollHeight);")Let us scroll ... Read More

Advertisements