Handle SSL Certificate Error Using Selenium WebDriver

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:56:05

1K+ Views

We can handle SSL certificate error using Selenium webdriver while we try to launch a web page based on HTTP. SSL certificate errors are encountered in multiple browsers like Chrome, Safari, and Firefox and so on.SSL certificate error comes up if the site we are making an attempt to access has an outdated, invalid or an untrusted certificate. SSL or Secure Sockets Layer is a protocol followed to create a connection between the client (browser) and the server.To handle the SSL certificate error we have to use the DesiredCapabilities class and then accept the SSL error by setting the ACCEPT_SSL_CERTS ... Read More

Scroll Down in a Webpage Using Selenium WebDriver in Python

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:49:19

3K+ Views

Yes it is possible to scroll down in a webpage using Selenium webdriver in Python by using the JavaScript Executor. Selenium can execute JavaScript commands with the help of execute_script method.The JavaScript command to be used is passed as a parameter to this method. Also, it must be noted that scrolling actions cannot be performed directly with any methods in Selenium.To scroll down in a page to the end, we have to pass the command window.scrollTo as a parameter to the execute_script method. Also, the values 0 and document.body.scrollHeight are passed as parameters to the window.scrollTo command.Syntaxdriver.execute_script("window.scrollTo(0, document.body.scrollHeight);")Let us scroll ... Read More

Automate Right-Click Menu Box Pop-Up in Python Selenium

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:48:55

909 Views

We can automate right click action with Selenium webdriver in Python by using the ActionChains class. We have to create an object of the ActionChains class and then apply the relevant method on it.In order to move the mouse to the element on which right click is to be performed, we shall use the move_to_element method and pass the element locator as a parameter.Then apply context_click method to perform the right click. Finally, use the perform method to actually carry out these actions. Also, we have to add the statement from selenium.webdriver.common.action_chains import ActionChains in our code to work with ... Read More

Perform Mouse Hover Action in Selenium Python

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:46:17

17K+ Views

We can perform mouseover action in Selenium webdriver in Python by using the ActionChains class. We have to create an object of this class and then apply suitable methods on it.In order to move the mouse to an element, we shall use the move_to_element method and pass the element locator as a parameter. Then apply the perform method to actually perform this action. After hovering on the element, we can apply click action on it with the help of the click method.Syntaxa = ActionChains(driver) m= driver.find_element_by_link_text("Enabled") a.move_to_element(m).perform()Let us try to hover on the element Enabled as shown on the below ... Read More

Selenium Wait Until Document is Ready

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:44:07

6K+ Views

We can wait until the document is ready (page loaded completely) in Selenium by applying the method pageLoadTimeout. The wait time is passed as a parameter to this method.The webdriver waits for this duration for the page to load completely. If this time gets elapsed without page loading, a TimeoutException is thrown.Syntaxdriver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS);ExampleCode Implementation with pageLoadTimeoutimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class PageLdTime{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       //page load ... Read More

Scroll Element to the Middle of the Screen with Selenium

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:42:35

4K+ Views

We can scroll to the middle of the screen with Selenium webdriver using the JavaScript Executor. Selenium can execute JavaScript commands with the help of the executeScript method.To scroll to the middle of the screen, we have to first identify the element upto which we want to scroll on the page. Then pass scrollIntoView and the web element as parameters to the executeScript method.JavaScript command scrollIntoView can have multiple optional parameters. They are −behavior – This can have the values - smooth or auto. It describes the animation of the transition. The default value is auto.block – This can have ... Read More

Download Microsoft WebDriver Edge Driver for Selenium

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:29:20

4K+ Views

We can download Microsoft/Edge Driver to use with Selenium. The Microsoft Edge driver allows communication of the tests developed in Selenium with the Edge browser.To download the msedgedriver.exe file, we have to first navigate to the following link − https://developer.microsoft.com/en-us/microsoftedge/tools/webdriver/#downloadsThen move to the Downloads section, and click on the link based on the local operating system and browser version we have.Once the download is completed, a zip file gets saved. It needs to be extracted and stored in a location. After extracting it, the executable file - msedgedriver.exe file is to be kept at a desired location.We have to configure ... Read More

Best Way to Handle JavaScript Popup Using Selenium WebDriver

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:28:04

577 Views

We can handle a JavaScript pop-up using Selenium webdriver with the help of the Alert interface. The alerts are pop-ups that shift the focus from the main webpage to the alert text appearing on the page.By default, the webdriver has focus on the main page, to access the alert we have to explicitly switch the driver focus from the main page to the alert box. The alerts can be of two types – web based and window based. JavaScript pop-ups are the web based alerts.The switchTo().alert() method is used to switch the driver focus to the alert. Once the driver ... Read More

Avoid StaleElementReferenceException in Selenium

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:27:24

590 Views

The StaleElementReferenceException is thrown if the webdriver makes an attempt to access a web element which is currently not available or invalid in DOM.This can be due to refresh of the page or an element is accidentally deleted or modified or no longer connected to DOM. This type of exception can be avoided by following the below techniques −Page refresh.Having a retry mechanism.Having a try-catch block.Waiting for some expected criteria like presenceOfElementLocated or refreshing a page on getting a stale condition for an element.ExampleCode Implementation having StaleElementExceptionimport 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 StaleElemntExc{   ... Read More

SendKeys Not Working in Selenium WebDriver

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:26:50

6K+ Views

If we encounter issues while working with the sendKeys method, then we can use the JavaScript Executor to input text within an edit box. Selenium can run JavaScript commands with the help of the executeScript method.JavaScript command to be used is passed as a parameter to this method. To input text we shall first identify the edit field with the JavaScript method document.getElementsByClassName. Then apply the value method on it.Let us try to enter text tutorialspoint to the below Google search box −SyntaxJavascriptExecutor j = (JavascriptExecutor) driver; j.executeScript("document.getElementsByName('qwe')[0].value= 'tutorialspoint'");Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.JavascriptExecutor; ... Read More

Advertisements