Get Title and URL of a Webpage with JavaScript Executor in Selenium with Python

Debomita Bhattacharjee
Updated on 28-Jul-2020 15:13:43

1K+ Views

We can get the title and URL of a webpage with Javascript executor in Selenium. Javascript is a language used for scripting and runs on the client side (on the browser). Selenium gives default methods to work with Javascript.Syntaxprint(driver.execute_script('return document.title')) print(driver.execute_script('return document.URL'))There are couple of methods of working with Javascript −Javascript execution at document root level.In this process, we shall identify the element with locators (class or id) and then perform the required action on it. Then execute_script() method is called and the Javascript is passed as a string to it.Syntaxjavas = "document.getElementsByName('user-search')[0].click();" driver.execute_script(javas)Please note, we have used getElementsByName('user-search')[0]. The ... Read More

Get Inner Text of Webpage with JavaScript Executor in Selenium using Python

Debomita Bhattacharjee
Updated on 28-Jul-2020 15:10:51

3K+ Views

We can get the inner text of a webpage with a Javascript executor in Selenium. Javascript is a language used for scripting and runs on the client side (on the browser). Selenium gives default methods to work with Javascript.Syntaxprint(driver.execute_script('return document.documentElement.innerText'))There are couple of methods of working with Javascript −Javascript execution at document root level.In this process, we shall identify the element with locators (class or id) and then perform the required action on it. Then execute_script() method is called and the Javascript is passed as a string to it.Syntaxjavas = "document.getElementsByName('user-search')[0].click();" driver.execute_script(javas)Please note, we have used getElementsByName('user-search')[0]. The functions like ... Read More

Vertical Scrolling of a Webpage with JavaScript Executor in Selenium with Python

Debomita Bhattacharjee
Updated on 28-Jul-2020 14:54:54

569 Views

We can perform vertical scrolling of a webpage with Javascript executor in Selenium. Javascript is a language used for scripting and runs on the client side (on the browser). Selenium gives default methods to work with Javascript.Syntaxdriver.execute_script("window.scrollTo(0, document.body.scrollHeight);")There are couple of methods of working with Javascript −Javascript execution at document root level.In this process, we shall identify the element with locators (class or id) and then perform the required action on it. Then execute_script() method is called and the Javascript is passed as a string to it.Syntaxjavas = "document.getElementsByName('user-search')[0].click();" driver.execute_script(javas)Please note, we have used getElementsByName('user-search')[0]. The functions like getElementsByName and ... Read More

Click Button with JavaScript Executor in Selenium with Python

Debomita Bhattacharjee
Updated on 28-Jul-2020 14:49:42

10K+ Views

We can click on a button with a Javascript executor in Selenium. Javascript is a language used for scripting and runs on the client side (on the browser). Selenium gives default methods to work with Javascript.Syntaxb = driver.find_element_by_xpath("//input[starts-with(@class, 'gsc')]") driver.execute_script("arguments[0].click();", b)There are couple of methods by which Javascript can be executed within browser −Javascript execution at document root level.In this process, we shall identify the element with locators (class or id) and then perform the required action on it. Then execute_script() method is called and the Javascript is passed as a string to it.Syntaxjavas = "document.getElementsByName('user-search')[0].click();" driver.execute_script(javas)Please note, we have ... Read More

Maximize Array Sum with Arr + Arr in C++

Sunidhi Bansal
Updated on 28-Jul-2020 11:33:10

527 Views

We are given with an array of integers. The goal is to maximize the value of expression −arr[j]-arr[i] + arr[l]-arr[k] ; i

Maximize the Value of X + Y + Z in C++

Sunidhi Bansal
Updated on 28-Jul-2020 11:30:49

392 Views

We are given with integers a, b, c, n. The goal is to maximize the sum of x, y and z such that ax+by+cz=n.From above formula, cz=n-(ax+by) z= (n- (ax+by))/cBy fixing x and y, calculate z using the above formula, for each x, y and z. Calculate sum and store the maximum such sum obtained.Inputn = 6, a = 3, b = 4, c = 5;Outputmaximum x+y+z is 2.Explanation − for x=2, y=0 and z=0 ax+by+cz=n.3*2+0*4+0*5=6 = nInputn = 4, a = 3, b = 1, c = 2;Outputmaximum x+y+z=4Explanation − for x=0, y=4 and z=4 ax+by+cz=n.0*3+4*1+0*2=4 = nApproach used ... Read More

Maximum Mirrors to Transfer Light from Bottom to Right in C++

Sunidhi Bansal
Updated on 28-Jul-2020 11:28:57

228 Views

We are given with a square matrix which contains 0’s and 1’s only. 0 represents a blank or empty place and 1 means obstacle. We must find a number of mirrors that can be placed at empty cells such that these mirrors can transfer light from bottom to right. This is possible when, mirror is placed at index [i, j] and for all cells on the right in that particular row ( i ) and cells in the bottom ( j ) in that particular column have no obstacle.If the mirror is at A[i][j], then all A[i+1 to n][ j ... Read More

Maximum Number by Concatenating Elements in a Rotation of an Array in C++

Sunidhi Bansal
Updated on 28-Jul-2020 11:25:59

761 Views

We are given a circular array of numbers. A circular array is the one in which the elements are arranged such that the first element is treated as just next to the last element. These are used to implement queues.Each element has the same or different digit count. The goal is to create the highest number possible by concatenating the numbers, using rotation of elements if required. We will do this by finding the highest leftmost digit among all the leftmost digits of all elements. The number with the highest leftmost digit will take the first place.If it is at ... Read More

Count Columns Not Sorted in Increasing Order in C++

Sunidhi Bansal
Updated on 28-Jul-2020 11:24:04

267 Views

We are given an array of strings each of the same length. The goal is to find columns, ( matrix of strings ) that are not sorted in increasing order. For example, each first character in string is compared with the first character of the next string and so on till the last string. If they are not in increasing order, increase the count. Do this for all second characters, then third characters of all strings and so on till the last character.InputArr[]= { “abc”, “bcd”, “def” }OutputCount of columns: 0Explanation − for each column,Column 1: character at index 0 : a

Count Minimum Steps to Get the Desired Array in C++

Sunidhi Bansal
Updated on 28-Jul-2020 11:22:13

380 Views

We are given with an array target[] which has numbers in it. We must find the minimum steps in which array with all zeros [0, 0, 0, 0…] can be converted to target using following two operations only −Increment operation − all elements can be incremented by 1, each increment operation can be counted individually in steps. ( for n increments in n elements steps=n )Doubling operation − the whole array is doubled. For all elements it is counted once. ( each doubling operation doubles all elements’ value, count it as 1 in stepsThe goal is to find the minimum ... Read More

Advertisements