We can select the text of a span on click with Selenium webdriver. To identify the element with span tag, we have to first identify it with any of the locators like xpath, css, class name or tagname.After identification of the element, we can perform the click operation on it with the help of the click method. Then obtain its text with the text method. Let us investigate the html code of a webelement with a span tag.Examplefrom selenium import webdriver #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) #launch URL driver.get("https://www.tutorialspoint.com/index.htm") #identify element and enter text e = driver.find_element_by_class_name("search") e.send_keys("tutorialspoint@gmail.com") ... Read More
We can locate elements in span class and not unique id with the help of the Selenium webdriver. We can identify an element having a class attribute with the help of the locator xpath, css or class name.To locate elements with these locators we have to use the By.xpath, By.xpath or By.cssSelector method. Then pass the locator value as a parameter to this method.Let us see the html code of a button having a span class and try to identify it.Examplefrom selenium import webdriver #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) #launch URL driver.get("https://www.tutorialspoint.com/index.htm") l = driver.find_element_by_id("textemail") l.send_keys("abc@gmail.com") #get value ... Read More
We can handle plugin popup using Selenium webdriver in Python. Whenever a popup comes on page, we cannot inspect elements within the popup and identify them.Also, in order to access other elements on the page, we have to first either accept default has access to the main page. To interact with the popup, we have to explicitly shift the driver focus with the help of the switch_to.alert() method.The popup mainly consists of a message along with Ok and Cancel buttonsto accept and dismiss a popup respectively. To accept a popup, the method switch_to.alert().accept() is used.To dismiss a popup, the method ... Read More
We can find elements by multiple class names. If there is an element having more than one value separated by spaces set for the class attributes, it is called the compound class names.Let us see the HTML code of such web elements having compound class names −We shall get an exception if we use both the values - toc and chapters with the class name locator for the above scenario. Instead, the rule is to have only one class attribute value with the class name locator.SyntaxWebElement l = driver.findElement(By.className("toc")); //Invalid locator value with className locator WebElement l = driver.findElement(By.className("toc chapters"));Exampleimport ... Read More
We can prioritize tests in TestNG during execution. It must be noted that priority can only be set for test methods with @Test annotation. Lower the priority number set for a test method, higher the priority it gets during execution.Only integer value (positive, zero or negative) can be set as priority. A decimal number can also be set as priority, however it is required to be converted to integer value via typecasting.A test method cannot have multiple priority numbers. Also, the priority for a test method cannot be set from the TestNG XML file.Syntaxpublic class TestNG { @Test (priority ... Read More
We may encounter Cannot find class in classpath exception while executing tests in Selenium with TestNG framework. This can be caused because of the following reasons −In the TestNG XML, the class tag having the name attribute should not have the .java extension.In the TestNG XML, the class file is incorrect and hence unable to determine the classpath of the class.Errors within the project are present, and may require a clean project.In the TestNG XML, the class file name is incorrectThe below image shows an example of this error −Exampleimport org.testng.annotations.Test; public class TestNGP { @Test public void ... Read More
We can run multiple test cases using TestNG test suite in Selenium webdriver. To execute test cases simultaneously, we have to enable parallel execution in TestNG.A TestNG execution is driven by the TestNG xml file. To trigger parallel execution we have to use the attributes – parallel and thread-count. The attribute threadcount controls the number of threads to be triggered while executing the tests in a parallel mode. The values that can be set for parallel attributes are – tests, classes, instances and methods.Exampleimport org.testng.annotations.Test; public class TestNG15 { @Test public void tC1() { System.out.println("Test ... Read More
Cucumber dry run is used for compilation of the Step Definition and Feature files and to verify the compilation errors. The value of dry run can be either true or false. The default value of dry run is false and it is a part of the Test Runner Class file.In case the value of dry run is set to true, Cucumber will verify individual steps in the Feature file and the implementation code of steps in Feature file within the Step Definition file.A message is thrown, if any of the steps in the Feature file is not implemented in the ... Read More
ProblemJavaScript function that takes in a 2-D array, arr, as the first and the only argument.Each subarray of our input array is an array of exactly two numbers, specifying a time interval.Our function should remove all intervals that are covered by another interval in the array arr. Interval [a,b) is covered by interval [c,d) if and only if c (a === c ? d - b : a - c)); let last = arr[0]; let count = arr.length; for(let i = 1; i < arr.length; i++){ const [a, b] = last; const [c, d] = arr[i]; if(c >= a && d
ProblemJavaScript function that takes in an array of integers sorted in increasing order, arr.There is exactly one integer in the array that occurs more than one fourth times (25%) of the times, our function should return that number.For example, if the input to the function is −const arr = [3, 5, 5, 7, 7, 7, 7, 8, 9];Then the output should be −const output = 7;Example Live DemoThe code for this will be −const arr = [3, 5, 5, 7, 7, 7, 7, 8, 9]; const oneFourthElement = (arr = []) => { const len = arr.length / 4; const search = (left, right, target, direction = 'left') => { let index = -1 while (left