Found 719 Articles for Testing Tools

sendKeys() not working in Selenium Webdriver

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

5K+ 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

How to submit a form in Selenium webdriver if submit button can't be identified?

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

2K+ Views

We can submit a form in Selenium webdriver even if the submit button cannot be identified. This can be achieved by locating any element within the form tag and the applying submit method on it. A form in the html code is identified by the tag.Let us investigate the html code of element with in a form tag −In the above example, we shall try to submit the form with the help of the Email or Password field and not by clicking on the Sign in button.Syntaxdriver.findElement(By.className("input__input")).sendKeys("96968547"); driver.findElement(By.className("session_password")).sendKeys("test123"); driver.findElement(By.className("session_password")).submit();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; public ... Read More

How to Scroll Down or UP a Page in Selenium Webdriver?

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

9K+ Views

We can scroll down or up a page in Selenium webdriver using JavaScript Executor. Selenium can execute JavaScript commands with the help of the executeScript method.To scroll down vertically in a page we have to use the JavaScript command window.scrollBy. Then pass the pixel values to be traversed along the x and y axis for horizontal and vertical scroll respectively.The positive value set for x-axis shall scroll the page to the right while the negative value for x-axis shall scroll it to the left. Similarly, the positive value set for y-axis shall scroll down the page while the negative value ... Read More

How to click on sign up button using Java in Selenium I am able to open page but not able to click?

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

4K+ Views

We can click on the Sign up button using Java in Selenium. First of all, we have to identify the Sign up button with the help of any of the locators like id, class name, name, link text, xpath, css or partial link text. After identification, we have to click on the Sign up the button with the help of the method click.SyntaxWebElement m=driver. findElement(By.id("loc-txt")); m.click();ExampleCode Implementation with clickimport 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; public class SignIn{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver", ... Read More

Need to wait until page is completely loaded - Selenium WebDriver

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

5K+ Views

We can wait until the page is completely loaded in Selenium webdriver by using the JavaScript Executor. Selenium can run JavaScript commands with the help of the executeScript method.We have to pass return document.readyState as a parameter to the executeScript method and then verify if the value returned by this command is complete.SyntaxJavascriptExecutor j = (JavascriptExecutor)driver; if (j.executeScript("return document.readyState").toString().equals("complete")){    System.out.println("Page has loaded"); }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; public class PageLdWait{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe");   ... Read More

How to Handle alerts in Selenium?

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

3K+ Views

We can handle alerts in Selenium webdriver by using the Alert interface. An alert can be of three types – a prompt which allows the user to input text, a normal alert and a confirmation alert.By default, the webdriver can only access the main page, once an alert comes up, the method switchTo().alert() is used to shift the focus webdriver control to the alert.A normal alert is shown below −A confirmation alert is shown below −A prompt alert is shown below −To accept an alert (to click on the OK button in alert), the method switchTo().alert().accept() is used. To dismiss ... Read More

How to stop a page loading from Selenium in chrome?

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

8K+ Views

We can stop a page loading with Selenium webdriver in Chrome browser by using the JavaScript Executor. Selenium can execute JavaScript commands with the help of the executeScript command.To stop a page loading, the command window.stop() is passed as a parameter to the executeScript method. Also, for the Chrome browser we have to configure the pageLoadStrategy to none value and wait for the web element to be available.Finally, we have to invoke window.stop.Syntaxdriver.execute_script("window.stop();")ExampleCode Implementation with JavaScript Executorfrom selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By #configure pageLoadStrategy ... Read More

How to refresh a webpage using Python Selenium Webdriver?

Debomita Bhattacharjee
Updated on 06-Apr-2021 10:58:56

17K+ Views

We can refresh a webpage using Selenium webdriver in Python. This can be done with the help of the refresh method. First of all, we have to launch the application with the get method.Once a web page is loaded completely, we can then refresh the page with the help of the refresh method. This way the existing page gets refreshed. The refresh method is to be applied on the webdriver object.Syntaxdriver.get("https://www.tutorialspoint.com/tutor_connect/index.php") driver.refresh()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.google.com/") #identify text box m = driver.find_element_by_class_name("gLFyf") #send input m.send_keys("Java") #refresh page driver.refresh()OutputRead More

Can we get the HTTP Response Code in Selenium with Java?

Debomita Bhattacharjee
Updated on 06-Apr-2021 10:58:29

2K+ Views

We can get the HTTP response code in Selenium webdriver with Java. Some of the response codes are – 2xx, 3xx, 4xx and 5xx. The 2xx response code signifies the proper condition, 3xx represents redirection, 4xx shows resources cannot be identified and 5xx signifies server problems.To obtain the response code we shall use the HttpURLConnection class. To have a link to the URL, the method openConnection is used. Also, we have to use the setRequestMethod where the vale Head is to be passed as a parameter.We have to create an instance of the HttpURLConnection class and then apply the connect ... Read More

What is the primary difference between the XPath and CSS selector in Selenium?

Debomita Bhattacharjee
Updated on 06-Apr-2021 10:57:45

4K+ Views

There are some differences between the xpath and css selector. The format of xpath is //tagname[@attribute='value'] while the format of css selector is tagname[attribute='value'].We can traverse both forward and backward in DOM, i.e we can move from parent to child element and also from child to the parent element with xpath. However for css, we can only traverse from parent to child and not vice-versa.In terms of performance, css is better and faster, while xpath is on a slower side. An xpath can be of two types – absolute which starts from the root node and relative does not require ... Read More

Advertisements