Found 9321 Articles for Object Oriented Programming

How can we handle authentication popup in Selenium WebDriver using Java?

Debomita Bhattacharjee
Updated on 18-Nov-2021 11:48:54

1K+ Views

We can handle authentication popup in Selenium webdriver using Java. To do this, we have to pass the user credentials within the URL. We shall have to add the username and password to the URL.Syntax −https://username:password@URL https://admin:admin@the-internet.herokuapp.com/basic_auth Here, the admin is the username and password. URL – www.the-internet.herokuapp.com/basic_auth Let us work and accept the below authentication popup.ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver;    public class AuthnPopup{       public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String u = "admin";   ... Read More

How to scroll down a webpage in selenium using Java?

Debomita Bhattacharjee
Updated on 18-Nov-2021 11:43:33

638 Views

We can scroll down a webpage in Selenium using Java. Selenium is unable to handle scrolling directly. It takes the help of the Javascript Executor to perform the scrolling action up to an element.First of all, we have to locate the element up to which we have to scroll. Next, we shall use the Javascript Executor to run the Javascript commands. The method executeScript is used to run Javascript commands in Selenium. We shall take the help of the scrollIntoView method in Javascript and pass true as an argument to the method.Syntax −WebElement elm = driver.findElement(By.name("name")); ((JavascriptExecutor) driver) .executeScript("arguments[0].scrollIntoView(true);", elm);Exampleimport ... Read More

Difference Between Inheritance and Polymorphism

Kiran Kumar Panigrahi
Updated on 21-Feb-2023 14:55:03

6K+ Views

In computer programming, Inheritance and Polymorphism are two important concepts. The most basic difference between inheritance and polymorphism is that "inheritance" is a concept of objectoriented programming that allows creating a new class with the help of the features of an existing class, whereas the concept "polymorphism" represents multiple forms of a single function. Read this article to learn more about Inheritance and Polymorphism and how they are different from each other. What is Inheritance? Inheritance is a concept in object-oriented programming (OOP) that refers to the process by which an object can take on the features of one or ... Read More

Difference Between Top-down and Bottom-up Approach

Kiran Kumar Panigrahi
Updated on 06-Sep-2023 21:26:28

49K+ Views

In the top-down approach, a bigger module/problem is divided into smaller modules. In contrast, in the bottom-up approach, the smaller problems are solved and then they are integrated to find the solution of a bigger problem. Read this article to learn more about top-down approach and bottom-up approach and how they are different from each other. What is Top-Down Approach? Top-Down Approach is an approach to design algorithms in which a bigger problem is broken down into smaller parts. Thus, it uses the decomposition approach. This approach is generally used by structured programming languages such as C, COBOL, FORTRAN. The ... Read More

Count occurrences of a substring recursively in Java

Sunidhi Bansal
Updated on 05-Jan-2021 04:54:47

8K+ Views

Given two strings str_1 and str_2. The goal is to count the number of occurrences of substring str2 in string str1 using a recursive process.A recursive function is the one which has its own call inside it’s definition.If str1 is “I know that you know that i know” str2=”know”Count of occurences is − 3Let us understand with examples.For ExampleInputstr1 = "TPisTPareTPamTP", str2 = "TP";OutputCount of occurrences of a substring recursively are: 4ExplanationThe substring TP occurs 4 times in str1.Inputstr1 = "HiHOwAReyouHiHi" str2 = "Hi"OutputCount of occurrences of a substring recursively are: 3ExplanationThe substring Hi occurs 3 times in str1.Approach used ... Read More

Construct an identity matrix of order n in JavaScript

AmitDiwan
Updated on 11-Dec-2020 09:47:53

692 Views

Identity MatrixAn identity Matrix is a matrix which is n × n square matrix where the diagonal consist of ones and the other elements are all zeros.For example an identity matrix of order is will be −const arr = [    [1, 0, 0],    [0, 1, 0],    [0, 0, 1] ];We are required to write a JavaScript function that takes in a number, say n, and returns an identity matrix of n*n order.ExampleFollowing is the code −const num = 5; const constructIdentity = (num = 1) => {    const res = [];    for(let i = 0; ... Read More

Return Vowels in a string in JavaScript

AmitDiwan
Updated on 11-Dec-2020 09:46:17

597 Views

We are required to write a JavaScript function that takes in a string that might contain some alphabets. The function should count and return the number of vowels that exists in the string.ExampleFollowing is the code −const str = 'this is a string'; const countVowels = (str = '') => {    str = str.toLowerCase();    const legend = 'aeiou';    let count = 0;    for(let i = 0; i < str.length; i++){       const el = str[i];       if(!legend.includes(el)){          continue;       };       count++;    };    return count; }; console.log(countVowels(str));OutputFollowing is the output on console −4

JavaScript function that generates all possible combinations of a string

AmitDiwan
Updated on 11-Dec-2020 09:45:26

615 Views

We are required to write a JavaScript function that takes in a string as the only argument. The function should generate an array of strings that contains all possible contiguous substrings that exist in the array.ExampleFollowing is the code −const str = 'Delhi'; const allCombinations = (str1 = '') => {    const arr = [];    for (let x = 0, y=1; x < str1.length; x++,y++) {       arr[x]=str1.substring(x, y);    };    const combination = [];    let temp= "";    let len = Math.pow(2, arr.length);    for (let i = 0; i < len ; i++){       temp= "";       for (let j=0;j

JavaScript function to convert Indian currency numbers to words with paise support

AmitDiwan
Updated on 11-Dec-2020 09:44:14

2K+ Views

We are required to write a JavaScript function that takes in a floating-point number up to 2 digits of precision.The function should convert that number into the Indian current text.For example −If the input number is −const num = 12500Then the output should be −const output = 'Twelve Thousand Five Hundred';ExampleFollowing is the code −const num = 12500; const wordify = (num) => {    const single = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"];    const double = ["Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"];    const tens = ["", "Ten", "Twenty", "Thirty", ... Read More

Calculate the hypotenuse of a right triangle in JavaScript

AmitDiwan
Updated on 11-Dec-2020 09:40:27

548 Views

We are required to write a JavaScript function that takes in two numbers. The first number represents the length of the base of a right triangle and the second is perpendicular. The function should then compute the length of the hypotenuse based on these values.For example −If base = 8, perpendicular = 6Then the output should be 10ExampleFollowing is the code −const base = 8; const perpendicular = 6; const findHypotenuse = (base, perpendicular) => {    const bSquare = base ** 2;    const pSquare = perpendicular ** 2;    const sum = bSquare + pSquare;    const hypotenuse = Math.sqrt(sum);    return hypotenuse; }; console.log(findHypotenuse(base, perpendicular)); console.log(findHypotenuse(34, 56));OutputFollowing is the output on console −10 65.5133574166368

Advertisements