Screenshot of a Particular Element with Python Selenium in Linux

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:45:08

572 Views

We can capture a screenshot of a particular element with Selenium webdriver in Python. To achieve this task, first we have to identify the element which we want to identify with the help of any locators like id, xpath, css, name, class name, tagname, link text or partial link text.After the element has been identified, we can capture its screenshot with the help of the screenshot method. We have to pass the file name where the screenshot shall be stored (along with extension) as a parameter to this methodSyntaxm=driver.find_element_by_tag_name("h4") m.screenshot("logo.png")Let us capture the screenshot of the highlighted text below −Examplefrom ... Read More

WebDriverException: Chromedriver Executable Needs to be in PATH

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:44:22

2K+ Views

We can get the error selenium.common.exceptions.WebDriverException if the path of the chromedriver.exe executable file is not set properly or incorrect within the webdriver.Chrome(). The below image shows such an exception.It can be resolved by the following ways −Verify the path of the chromedriver.exe file set within webdriver.Chrome.Install the webdriver manager with the command: pip install webdrivermanager. Then add the statement: from webdriver_manager.chrome import ChromeDriverManager in our code.ExampleCode Implementation with webdriver managerfrom selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager #configure webdriver manager driver = webdriver.Chrome(ChromeDriverManager().install()) driver.implicitly_wait(0.5) #launch URL driver.get("https://www.tutorialspoint.com/index.htm") print("URL is: ") print(driver.current_url) driver.close()OutputRead More

Handle SSL Certificate in Safari with Selenium WebDriver

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:43:55

363 Views

Selenium webdriver is capable of handling SSL certificate in the Safari browser. This is done with the help of the DesiredCapabilities class. We shall create an object of this class. Then apply the setCapability method on it and set the value of property CapabilityType.ACCEPT_SSL_CERTS to true.The SSL is a protocol developed to have a secure connection between the server and the client browser. It verifies the website authenticity before any further communication with it.SyntaxDesiredCapabilities pc = DesiredCapabilities.safari(); pc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.safari.SafariDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.remote.DesiredCapabilities; public class SSLErrorSafari{    public static void main(String[] args) { ... Read More

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

368 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

886 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

393 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

Advertisements