Articles on Trending Technologies

Technical articles with clear explanations and examples

sendKeys() not working in Selenium Webdriver

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 06-Apr-2021 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

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

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 06-Apr-2021 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
Debomita Bhattacharjee
Updated on 06-Apr-2021 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
Debomita Bhattacharjee
Updated on 06-Apr-2021 5K+ 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
Debomita Bhattacharjee
Updated on 06-Apr-2021 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 stop a page loading from Selenium in chrome?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 06-Apr-2021 10K+ 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
Debomita Bhattacharjee
Updated on 06-Apr-2021 20K+ 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()Output

Read More

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

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 06-Apr-2021 5K+ 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

How to extract text from a web page using Selenium and save it as a text file?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 06-Apr-2021 5K+ Views

We can extract text from a webpage using Selenium webdriver and save it as a text file using the getText method. It can extract the text for an element which is displayed (and not hidden by CSS).We have to locate the element on the page using any of the locators like id, class, name, xpath, css, tag name, link text or partial link text. Once the text is obtained, we shall write its content to a file with the help of File class.Let us obtain the text – You are browsing the best resource for Online Education from the below ...

Read More

Is it possible to manually set the attribute value of a Web Element using Selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 06-Apr-2021 4K+ Views

Yes it is possible to manually set the attribute value of a web element in Selenium webdriver using the JavaScript Executor. Selenium can run JavaScript commands with the help of the executeScript method.First, we shall identify the element on which we want to manually set the attribute value with the JavaScript command document.getElementsByClassname. Next to set the attribute we have to use the setAttribute method.Let us modify the background color of the button CHECK IT NOW to yellow. By default it is green on the page.The can be done by setting the style attribute of the background-color to yellow.SyntaxJavascriptExecutor j ...

Read More
Showing 49931–49940 of 61,297 articles
Advertisements