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
We can find a next sibling element from the same parent in Selenium webdriver. This is achieved with the help of xpath locator. It is important to note that it is only possible to traverse from current sibling to the next sibling with the help of xpath.To traverse to the next sibling, we have to use the following-sibling concept in xpath. This will allow us to traverse to the next sibling from the present sibling of the same parent.Syntax −driver.find_element_by_xpath("//div[@class='txt-bx']/following-sibling::p")Let us try to move from the first child of parent to the second as in the above image.ExampleCode ... Read More
We can click a link/button with its href link in Selenium webdriver. This can be achieved by multiple ways. We can use find_element_by_link_text() and find_element_by_partial_link_text() methods to perform this task.The find_element_by_link_text() method is used to identify an element with the text within the anchor tag as specified in the method parameter . If there is no matching text, NoSuchElementException is thrown.Syntaxfind_element_by_link_text("Coding Ground")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("Coding")ExampleCode Implementation with find_element_by_link_text().from selenium ... Read More
We can select/click the radio button with Selenium. In an html document, each radio button has an attribute type set to a value as radio. In order to select a radio button, we shall first identify it and then apply the click() method to it.ExampleCode Implementation.from selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") # maximize with maximize_window() driver.maximize_window() driver.get("https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm") # identify element and click() l=driver.find_element_by_xpath("//input[@value='2']") l.click() driver.close()Output