Search for a Keyword in Google Using Selenium Java

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:40:35

5K+ Views

We can search for a keyword in Google using Selenium webdriver in Java.In order, to perform a search, we have to first land on the Google page with the help of the get method.Then identify the search edit box with the help of any of the locators like id, name, class, xpath, tagname, or css. Then enter the keyword in the search box with the help of the sendKeys method.Finally, perform the keyword search by simulating ENTER keypress. This is done by using the sendKeys method and passing the parameter Keys.ENTER or Keys.RETURN.SyntaxWebElement r = driver.findElement(By.className("q")); r.sendKeys("Cypress"); r.sendKeys(Keys.RETURN);Exampleimport org.openqa.selenium.By; import ... Read More

Select Date from DatePicker using Selenium WebDriver in Python

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:40:10

10K+ Views

We can select a date from a datepicker with Selenium webdriver using Python. To identify a particular date, first we have to use the find_elements method and identify all the dates having a common locator value.The find_elements returns a list of matching elements. We have to iterate through this list and search for the date which meets our criteria. Once we get that date, we would select it. Then break out from this iteration.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://jqueryui.com/datepicker/") #switch to frame l = driver.find_element_by_xpath("//iframe[@class='demo-frame']") driver.switch_to.frame(l); #identify element inside frame d= driver.find_element_by_id("datepicker") ... Read More

Automate Calendar Using Selenium WebDriver for Testing

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:38:25

3K+ Views

We can automate a calendar using Selenium webdriver. It may be a bit difficult to automate tests on a calendar since the selection of day, month, and year can be different in web UI from one calendar to another.A calendar can be in the form of a dropdown selection or with backward and forward buttons to select up and down in dates or with any other features. Let us see an example of selection of the 03/02/2021(2nd March, 2021) date in the below calendar −In the above example, the calendar is within a table. A table is represented by ... Read More

Command to Register Gecko Driver in Selenium

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:36:49

409 Views

We can register a gecko driver with Selenium webdriver. For the Firefox versions greater than 47, we can execute tests in Firefox with the geckodriver.exe file. To download this executable file, visit the below link − https://github.com/mozilla/geckodriver/releasesNext, we have to choose the link of the zip file which is compatible with our local operating system. As the download of the zip file is done, it has to be extracted and the file – geckodriver.exe should be saved in a location.To register this geckodriver.exe file, we have to set the path of the geckodriver.exe file with the System.setProperty method. Also we ... Read More

Select Each DIV Separately with Selenium Having the Same Class

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:35:37

5K+ Views

We can select each div separately that have the same class with the help of the Selenium webdriver. Often in the html code, we find more than one div element having a class attribute with the same value.Let us see the html code of elements with div tag having the same value set for the class attribute (as highlighted in the image). The value of the class attribute is - colsm-5 col-xs-8 store-details sp-detail paddingR0.To identify each of these div elements separately, we shall use the method findElements and pass the value of the class attribute as a parameter to ... Read More

Load Chrome Extension Using Selenium WebDriver

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:31:48

934 Views

We can load an extension in Chrome browser using Selenium webdriver.While we are using the Chrome browser in our local system, we can add multiple extensions to it.However, while Chrome browser is launched by Selenium webdriver, those extensions which are available to our local browser may not be present. We have to explicitly add them with the help of the .crx file of the extensions.To add an extension for example, Momentum, navigate to the below link − https://chrome.google.com/webstore/category/extensions.Type Momentum in the search box and hit Enter. Select the correct option from the search results.As the next page is navigated, we ... Read More

Benefits of Using Selenium as an Automation Testing Tool

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:29:37

423 Views

The benefits of using Selenium as an automation testing tool are listed below −It is open-source and comes free without licensing cost.It can used be used with more than one programming languages like C#, Java, Python, JavaScript, and so on.It can be used in more than one platforms like Windows, Mac, Linux, and so on.It can be used for testing an application in more than one browser like Chrome, Firefox, IE, Safari, and so on.It has a big community assistance for resolving users' queries.It can support record and playback features with the help of Selenium IDE.It can reduce use of ... Read More

Select Text of a Span on Click in Selenium

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:28:57

20K+ Views

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

Locate Elements in Span Class Using Python and Selenium

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:28:32

5K+ Views

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

Handle Plugin Blocked Pop-Up Using Selenium with Python

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:27:59

3K+ Views

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

Advertisements