Testing Tools Articles

Page 43 of 52

Refreshing web page by WebDriver when waiting for specific condition.

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 1K+ Views

We can refresh a web page by Selenium webdriver when waiting for a specific condition. We can take the help of the driver.navigate().refresh() method to refresh the webpage.ExampleCode Implementation with refresh().import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class BrowserRefresh{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       driver.get("https://www.tutorialspoint.com/index.htm");       // refresh webpage with refresh method       driver.navigate().refresh();    } }We can refresh a webpage with the help of sendKeys method and then send Keys.F5 as an argument to the method. The sendKeys method is ...

Read More

How to close the whole browser window by keeping the webDriver active?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 865 Views

We can close the whole browser by keeping the webdriver active with the help of Selenium webdriver. To achieve this we have to use the close method. If there are multiple browsers open the close method shall only close the browser which is in focus but the webdriver session still remains alive.There is another method called quit. It closes all the opened browsers and terminates the browser session. At the end of the test execution, it is always a good practice to use the quit method to terminate the session properly and avoid memory leaks.If there is only one browser ...

Read More

How to get the content of href within some targeted class using selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 941 Views

We can get the content of href within some targeted class with Selenium webdriver. First of all we have to locate the element with an anchor tag having a specific class attribute value with the help of locators like xpath, css or classname.Then we have to take the help of getAttribute method and pass href as an argument to the method. Let us have a look at the html code of an element with an anchor tag having the class and href attribute. The href value of the element should be /account/register?hl=en.ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; ...

Read More

How to scroll a specific DIV using Selenium WebDriver with Java?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 6K+ Views

We can scroll a specific DIV using Selenium webdriver. Selenium cannot handle scrolling directly. It takes the help of the Javascript Executor to do scrolling action to a specific DIV.First of all we have to identify the specific DIV up to which we have to scroll to with the help of xpath or css locator. Next we shall take the help of the Javascript Executor to run the Javascript commands. The method executeScript is used to execute Javascript commands in Selenium. We have to use the scrollIntoView method in Javascript and pass true as an argument to the method.SyntaxWebElement m=driver.findElement(By.xpath("//div[@class='slick-track']")); ...

Read More

How to set Selenium Python WebDriver default timeout?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 7K+ Views

We can set default timeout with Selenium webdriver. The method set_page_load_timeout is used to have a timeout for the page loading. The wait time in seconds is passed as parameter to the method.Syntaxdriver.set_page_load_timeout(5)A TimeoutException is thrown if the page is still not loaded after the wait time is passed.We can use the implicit wait concept in synchronization to define the default timeout time. This is a global wait time and applied to every element in the page. The method implicitly_wait is used to define implicit wait. The wait time in seconds is passed as parameter to the method.Syntaxdriver.implicitly_wait(5);A TimeoutException is ...

Read More

How to use the gecko executable with Selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 368 Views

We can use gecko executable driver with Selenium webdriver. For the Mozilla version above 47, the geckodriver is used due to the presence of Marionette, which is the driver for automation in Mozilla. We can launch the Firefox by instantiating the object of FirefoxDriver class with the help of the below statement.WebDriver driver=new FirefoxDriver();Next we have to download the geckodriver and configure it to our project by following the below step by step processes −Navigate to the link − https://www.selenium.dev/downloads/ and move below the Browser text, there is a Firefox section available. Click on the Documentation link just below that.All the geckodriver ...

Read More

How to capture the screenshot of a specific element rather than entire page using Selenium Webdriver?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 2K+ Views

We can capture the screenshot of a specific element rather than the entire page using Selenium webdriver. There may be requirements in the project where we have to capture the screenshot of a particular webelement.First of all we shall capture the screenshot of the entire page and then crop it according to the dimension and location of the element. We shall take the help of the TakeScreenShot interface and use its getScreenshotAs method.SyntaxFile i = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);Next store the image in a file [for example, .jpeg, .png].FileUtils.copyFile(i, new File(""))ExampleCode Implementationimport 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; import java.io.File; ...

Read More

Select parent element of known element in Selenium.

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 15K+ Views

We can select the parent element of a known element with Selenium webdriver. First of all we have to identify the known element with the help of any of the locators like id, classname and so on. Then we have to identify its parent element with findElement(By.xpath()) method.We can identify the parent element from its child by localizing it with the child and then passing ( ./..) as a parameter to the findElement(By.xpath()). Let us identify the parent element with tagname ul from the child element with the tagname li in below html code −Also we can identify the parent element ...

Read More

Wait until page is loaded with Selenium WebDriver for Python.

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 2K+ Views

We can wait until the page is loaded with Selenium webdriver. There is a synchronization concept in Selenium which describes implicit and explicit wait. To wait until the page is loaded we shall use the explicit wait concept.The explicit wait is designed such that it is dependent on the expected condition for a particular behavior of an element. For waiting until the page is loaded we shall use the expected condition presence_of_element_loaded for a particular element. Once the wait time is elapsed, the timeout error shall be thrown.To implement explicit wait conditions, we have to take help of the WebDriverWait ...

Read More

How to handle windows file upload using Selenium WebDriver?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 3K+ Views

We can handle windows file upload with Selenium webdriver. This is achieved by the sendKeys method. We have to first identify the element which performs the file selection by mentioning the file path [to be uploaded].This is only applied to an element having a type attribute set to file as value along with the element tagname as input. The below html code shows the element with type = file value set.ExampleCode Implementationimport 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 WndsFileUpl{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver ...

Read More
Showing 421–430 of 517 articles
« Prev 1 41 42 43 44 45 52 Next »
Advertisements