Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Debomita Bhattacharjee
Page 20 of 59
Need to wait until page is completely loaded - Selenium WebDriver
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 MoreHow to stop a page loading from Selenium in chrome?
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 MoreHow to refresh a webpage using Python Selenium Webdriver?
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 MoreWhat is the primary difference between the XPath and CSS selector in Selenium?
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 MoreHow to extract text from a web page using Selenium and save it as a text file?
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 MoreIs it possible to manually set the attribute value of a Web Element using Selenium?
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 MoreIs navigate method available in Selenium Webdriver with Python?
The navigate method is not available in Selenium webdriver with Python.In order to navigate to a page, we can use the get method and pass the URL of the page that we want to launch as a parameter.In this method the webdriver waits till the webpage is completely loaded prior transferring the control to the next step in the test case. If the page that we are trying to load, has multiple AJAX calls after loading, then the webdriver becomes unaware when the page will ultimately load.We can use the different wait methods in synchronization to handle such a scenario. ...
Read MoreWhich exception is raised when an element is not found in an HTML DOM using XPath in Selenium?
If an element is not found in an HTML DOM using xpath, then the NoSuchElementException is raised. This exception is thrown when the webdriver makes an attempt to locate a web element which is absent from DOM. This is normally encountered if we create an incorrect xpath for an element.The below image shows an example of NoSuchElementException..Exampleimport 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 ElemntsText{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); ...
Read MoreHow to get the text from a website using selenium?
We can get the text from a website using Selenium webdriver USING the getText method. It helps to obtain the text for a particular element which is visible or the inner text (which is not concealed from the page).First of all, we have to identify the element on the page for which we want to get the text with the help of any locators like id, class, name, xpath, css, tag name, link text or partial link text.Let us try to retrieve the text - ENJOY PREMIUM CONTENT AT AFFORDABLE PRICE from the below page −SyntaxWebElement n =driver.findElement(By.tagName("h2")); String s ...
Read MoreHow to find an element using the “Link Text/Partial Link Text” in Selenium?
We can find an element using the link text or the partial link text in Selenium webdriver. Both these locators can only be applied to elements with the anchor tag.The link text locator matches the text inside the anchor tag. The partial link text locator matches the text inside the anchor tag partially. NoSuchElementException shall be thrown for both these locators if there is no matching element.SyntaxWebElement n =driver.findElement(By.partialLinkText("Coding")); WebElement l =driver.findElement(By.linkText("Coding Ground"));Let us find the below highlighted element CODING GROUND on the page −ExampleCode Implementation with linkTextimport 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 LnkTxt{ ...
Read More