We have a string that contains some repeated letters like this −const a = "fdsfjngjkdsfhhhhhhhhhhhfsdfsd";Our job is to write a function that returns the count of maximum consecutive same letters in a streak. Like in the above string the letter h appears for 11 times in a row consecutively, so our function should return 11 for this string.This problem is a good candidate for this sliding window algorithm, here a stable window will be the one that contains consecutive letters and one that contains different elements is unstable. The window tends to get stable by adding new letters at the ... Read More
Let’s say, we have to write an Array function, say prependN() that takes in a number n (n len){ return false; }; const deleted = this.splice(len - num, num); this.unshift(...deleted); return true; }; console.log(arr.reshuffle(4)); console.log(arr);OutputThe output in the console will be −true [ 'orange', 'yellow', 'magenta', 'cyan', 'blue', 'red', 'green' ]
We have two arrays of literals that contain some common values, our job is to write a function that returns an array with all those elements from both arrays that are not common.For example −// if the two arrays are: const first = ['cat', 'dog', 'mouse']; const second = ['zebra', 'tiger', 'dog', 'mouse']; // then the output should be: const output = ['cat', 'zebra', 'tiger'] // because these three are the only elements that are not common to both arraysLet’s write the code for this −We will spread the two arrays and filter the resulting array to obtain an array ... Read More
We can find specific lines in a table with Selenium webdriver. A table is identified in an html document with tag. Each table comprises a tag that represents rows and a tag to represent columns. To traverse through table rows and columns we use the method findElements().To count the total number of rows in table we use size() method available for list −List l=driver.findElements(By.tagName("tr")); int s= l.size();To count the total number of columns in table we use size() method available for list −List m=driver.findElements(By.tagName("td")); int t= m.size();Let us consider the below table and get the ... Read More
We can click on an element using javascript, Actions class and webdriver methods. Selenium can execute commands in Javascript with the help of the execute_script() method.We have to import org.openqa.selenium.JavascriptExecutor in our code to work with a javascript executor. In order to click an element, first we have to move to that element with mouse movements. We can execute mouse movement with the help of the Actions class in Selenium.We have to use the moveToElement() method. This method shall perform mouse movement till the middle of the element and then perform click followed by build() and perform() methods. We have ... Read More
We can find and click elements by title in Selenium webdriver. An element can be identified with a title attribute with xpath or css selector. With the xpath, the expression should be //tagname[@title='value']. In css, the expression should be tagname[title='value'].Let us take an html code for an element with a title attribute.The xpath to identify the element should be //a[@title='Tutorialspoint'] and the css expression should be a[title='Tutorialspoint']. Once the element is identified we can use the click() method for clicking on it.ExampleCode Implementation.from selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") # implicit wait for 5 seconds driver.implicitly_wait(5) # maximize with ... Read More
We can check if any alert exists with Selenium webdriver. An alert is designed on a webpage to notify users or to perform some actions on the alert. It is designed with the help of Javascript.An alert can be of three types – prompt, confirmation dialogue box or alert. Selenium has multiple APIs to handle alerts with an Alert interface. To check the presence of an alert we shall use the concept of explicit wait in synchronization.As we know, explicit wait is developed based on Expected condition for a specific element. For the alerts, we shall verify if alert_is_present exists ... Read More
A matrix can have one or more than one minimum and maximum values. Also, the size of the matrix can be just one column and multiple rows or thousands of columns and thousands of rows. The row number and column number for the minimum and maximum values in a matrix can be found by using the following syntax −For Maximumwhich(“Matrix_Name”==min(“Matrix_Name”),arr.ind=TRUE)For Minimum>which(“Matrix_Name”==max(“Matrix_Name”),arr.ind=TRUE)Example M1
We can click the OK button inside an alert window with Selenium webdriver. An alert is designed on a webpage to notify users or to perform some actions on the alert. It is designed with the help of Javascript.An alert can be of three types – prompt, confirmation dialogue box or alert. Selenium has multiple APIs to handle alerts with an Alert interface. To click on the Ok button on alert, first of all we have to switch to alert with switchTo().alert() method.Next, to click on the Ok button, we have to use accept() method. Please note we cannot identify ... Read More
We can click a link whose href has a certain substring in the Selenium webdriver. There are multiple ways to perform this action. We can use find_element_by_partial_link_text() method to click on a link having a substring.The find_element_by_partial_link_text() method is used to identify an element by partially matching with the text within the anchor tag as specified in the method parameter. If there is no matching text, NoSuchElementException is thrown.Syntax −find_element_by_partial_link_text("Tutors")Also we can use css selector to identify the element whose href has a substring via * symbol. This is called wild character notation and implies that a string contains a certain ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP