Found 519 Articles for Selenium

How to set style display of an html element in a selenium test?

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:05:29

2K+ Views

We can set the style display of an html element with Selenium webdriver. The DOM interacts with the elements on the page with the help of Javascript. Selenium executes the Javascript commands by taking the help of the executeScript method. The commands to be executed are passed as arguments to the method.Some operations like setting the style display be performed by Javascript Executor. The getElementById method can be used to locate the element. Then we have to apply the style.display method on the webelement and set the display type.Syntaxexecutor.executeScript ("document.getElementById('gsc-i-id1').style.display='block';");ExampleCode Implementation.import 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; ... Read More

How to get HTML code of a WebElement in Selenium?

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:03:40

3K+ Views

We can get the html code of a webelement with the help of Selenium webdriver. We can obtain the innerHTML attribute to get the HTML content of the web element.The innerHTML is an attribute of a webelement which is equal to the content that is present between the starting and ending tag. The getAttribute method is used for this and innerHTML is passed as an argument to the method.SyntaxString s = element.getAttribute('innerHTML');Let us see the below html code of an element. The innerHTML of the element shall be < You are browsing the best resource for Online Education.ExampleCode Implementationimport org.openqa.selenium.WebDriver; ... Read More

Selenium WebDriver StaleElementReferenceException.

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:01:51

622 Views

We have StaleElementReferenceException in Selenium webdriver. As the name suggests, the word stale refers to something which is not new and perished. There may be a scenario in which an element which was present in DOM previously is now no longer available due to modification in DOM.In such a condition, if we try to access that element then StaleElementReferenceException is thrown. This type of exception is encountered due to the below reasons −The element is not present in the DOM any more.The element has been removed totally.There are certain ways we can prevent a StaleElementReferenceException as described below −We can ... Read More

Selenium WebDriver and DropDown Boxes.

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:59:59

399 Views

We can handle dropdown with Selenium webdriver. The static dropdown in Selenium is handled with the Select class and the dropdown should be identified in the html code with the tag.Let us see the html code of a static dropdown.We have to add the import org.openqa.selenium.support.ui.Select statement in the code to work with the methods available in the Select class. The methods to select an option from the dropdown are listed below −selectByValue(val) – The option is selected whose value attribute matches with the argument passed to the method. This method can be used only if the dropdown option has ... Read More

Selenium and iframe in html.

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:58:02

368 Views

We can work with iframe in Selenium webdriver. A frame is defined with , or tag in html code. A frame is used to embed an HTML document within another HTML document.Selenium by default has access to the parent browser driver. In order to access a frame element, the driver focus has to shift from the main browser window to the frame. There are more than one methods to shift to frames −switchTo().frame(id) - The id or name of frame is passed as an argument.Syntax − driver.switchTo().frame("id"), switching to the frame with id.switchTo().frame(m) - The index of frame ... Read More

How to locate element by partial id match in Selenium?

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:56:06

8K+ Views

We can locate elements by partial id match with Selenium webdriver. This can be achieved while we identify elements with the help of xpath or css locator. With the css and xpath expression, we use the regular expression to match id partially.Let us have a look at the id of an element in its html code. The id attribute value is gsc-i-id1.With the css expression, we can use the * and perform a partial match with the id.The css value shall be input[id*='id']. This means the subtext id is present in the actual text gsc-i-id1. We can also use the ... Read More

Refreshing web page by WebDriver when waiting for specific condition.

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:50:34

776 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
Updated on 26-Oct-2020 06:47:27

595 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
Updated on 26-Oct-2020 06:45:11

700 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
Updated on 26-Oct-2020 06:43:16

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

Advertisements