Path with Smallest Sum in JavaScript

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

292 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

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

Automate Right-Click Menu Box Pop-Up in Python Selenium

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:48:55

934 Views

We can automate right click action with Selenium webdriver in Python by using the ActionChains class. We have to create an object of the ActionChains class and then apply the relevant method on it.In order to move the mouse to the element on which right click is to be performed, we shall use the move_to_element method and pass the element locator as a parameter.Then apply context_click method to perform the right click. Finally, use the perform method to actually carry out these actions. Also, we have to add the statement from selenium.webdriver.common.action_chains import ActionChains in our code to work with ... Read More

Perform Mouse Hover Action in Selenium Python

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:46:17

17K+ Views

We can perform mouseover action in Selenium webdriver in Python by using the ActionChains class. We have to create an object of this class and then apply suitable methods on it.In order to move the mouse to an element, we shall use the move_to_element method and pass the element locator as a parameter. Then apply the perform method to actually perform this action. After hovering on the element, we can apply click action on it with the help of the click method.Syntaxa = ActionChains(driver) m= driver.find_element_by_link_text("Enabled") a.move_to_element(m).perform()Let us try to hover on the element Enabled as shown on the below ... Read More

Selenium Wait Until Document is Ready

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:44:07

6K+ Views

We can wait until the document is ready (page loaded completely) in Selenium by applying the method pageLoadTimeout. The wait time is passed as a parameter to this method.The webdriver waits for this duration for the page to load completely. If this time gets elapsed without page loading, a TimeoutException is thrown.Syntaxdriver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS);ExampleCode Implementation with pageLoadTimeoutimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class PageLdTime{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       //page load ... Read More

Advertisements