Finding an Element in a Sub-Element in Selenium WebDriver

Debomita Bhattacharjee
Updated on 18-Sep-2020 14:06:39

11K+ Views

We can find an element in a sub-element with Selenium webdriver. First of all we need to identify the element with help of any of the locators like id, class, name, xpath or css. Then we have to identify the sub-element with the findElements(By.xpath()) method.We can identify the sub-element from the element, by localizing it with the element and then passing the expression (./child::*) as a parameter to the findElements(By.xpath())Syntaxelement.findElements(By.xpath("./child::*"))Let us identify the tagname of the sub-elements of element ul in below html code−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; public class SubElement{    public static ... Read More

Scroll Down the Page to End in Selenium WebDriver

Debomita Bhattacharjee
Updated on 18-Sep-2020 14:01:50

6K+ Views

We can scroll down the page till page end with Selenium webdriver.Selenium cannot directly scroll up or down with its methods. This is done with the Javascript Executor. DOM can interact with the elements with Javascript.Selenium runs the commands in Javascript with the execute_script() method. For scrolling till the page down, we have to pass (0, document.body.scrollHeight) as parameters to the method scrollTo().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 ScrollTillPageEnd{    public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url ... Read More

PHP Variable Functions

Malhar Lathkar
Updated on 18-Sep-2020 14:00:58

11K+ Views

IntroductionIf name of a variable has parentheses (with or without parameters in it) in front of it, PHP parser tries to find a function whose name corresponds to value of the variable and executes it. Such a function is called variable function. This feature is useful in implementing callbacks, function tables etc.Variable functions can not be built eith language constructs such as include, require, echo etc. One can find a workaround though, using function wrappers.Variable function exampleIn following example, value of a variable matches with function of name. The function is thus called by putting parentheses in front of variableExample Live ... Read More

Wait for IFrames to Load Completely in Selenium WebDriver

Debomita Bhattacharjee
Updated on 18-Sep-2020 13:58:32

5K+ Views

We can wait for the iframe to load completely with Selenium webdriver.First of all we need to identify the iframe with the help iframe id, name, number or webelement. Then we shall use the explicit wait concept in synchronization to wait for the iframe to load.We need to import org.openqa.selenium.support.ui.ExpectedConditions and import org.openqa.selenium.support.ui.WebDriverWait to incorporate expected conditions and WebDriverWait class. We will wait for the iframe to be loaded with the condition frameToBeAvailableAndSwitchToIt.Let us see an html document of a frame.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.support.ui.WebDriverWait; import org.openqa.selenium.support.ui.ExpectedConditions; public class FrameLoadWait{    public ... Read More

PHP User Defined Functions

Malhar Lathkar
Updated on 18-Sep-2020 13:57:22

22K+ Views

IntroductionPHP has a large number of built-in functions such as mathematical, string, date, array functions etc. It is also possible to define a function as per specific requirement. Such function is called user defined function.A function is a reusable block of statements that performs a specific task. This block is defined with function keyword and is given a name that starts with an alphabet or underscore. This function may be called from anywhere within the program any number of times.Syntax//define a function function myfunction($arg1, $arg2, ... $argn) {    statement1;    statement2;    ..    ..    return $val; } ... Read More

Test If an Element is Focused Using Selenium WebDriver

Debomita Bhattacharjee
Updated on 18-Sep-2020 13:41:53

5K+ Views

We can test if an element is focused with Selenium webdriver. This is determined with the help of the activeElement() method. First of all we need to identify the element with help of any of the locators like id, class, name, xpath or css.Syntaxdriver.switchTo().activeElement();Let us consider the below edit box and check if it is focused.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; public class ElementFocussed{    public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);       driver.get("https://www.tutorialspoint.com/index.htm");       // identify ... Read More

PHP Function Arguments

Malhar Lathkar
Updated on 18-Sep-2020 13:38:56

6K+ Views

IntroductionA function in PHP can be defined to accept input from calling environment/script in the form of arguments. These arguments are given as comma separeted list inside the parentheses in front of name of function. Note that while calling a function, same number of arguments must be passed to it.PHP supports calling a function by passing value, reference, arguments with default value and by passing variable number of arguments.function with argumentsIn following example, a function is defined with two formal arguments. When this function is called by passing the arguments by value. Arguments of function become its local variables. Hence, ... Read More

Find Radio Button Element by Value Using Selenium

Debomita Bhattacharjee
Updated on 18-Sep-2020 13:37:46

3K+ Views

We can find a radio button element by value with Selenium webdriver. A radio button in an html document has a tagname input and it has a type attribute set to radio. We can select a radio button by using the click() method after identifying it.Let us see the html code of a radio button. To identify it with a value attribute we have to use the xpath or css locator.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; public class RadioButnVal{    public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ... Read More

Return Highest Number from Object Properties Value in JavaScript

AmitDiwan
Updated on 18-Sep-2020 13:37:02

739 Views

Suppose, we have an object that contains rating of a property over some criteria like this −const rating = {    "overall": 92,    "atmosphere": 93,    "cleanliness": 94,    "facilities": 89,    "staff": 94,    "security": 92,    "location": 88,    "valueForMoney": 92 }We are required to write a JavaScript function that takes in one such object and returns the key value pair that has the highest value.For example, for this very object, the output should be −const output = {    "staff": 94 };ExampleFollowing is the code −const rating = {    "overall": 92,    "atmosphere": 93,   ... Read More

Find Indexes of Multiple Minimum Value in an Array in JavaScript

AmitDiwan
Updated on 18-Sep-2020 13:35:48

600 Views

Suppose we have an array of numbers like this −const arr = [1, 2, 3, 4, 1, 7, 8, 9, 1];Suppose we want to find the index of the smallest element in the array i.e. 1 above.For this, we can simply use −const min = Math.min.apply(Math, arr); const ind = arr.indexOf(min);The above code will successfully set ind to 0, which indeed is correct.But what we want to achieve is that if there are more than one minimum elements in the array, like in the above array (three 1s), then we should return an array containing all the indices of minimum ... Read More

Advertisements