Found 519 Articles for Selenium

Selenium Web Test Automation Framework Best Practices.

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:28:38

314 Views

The best practices for Selenium web test automation framework are listed below −Use of dynamic waits like implicit wait and explicit wait instead of using Thread.sleep in the framework to handle sync issues in the application.Usage of Page Object Model framework design to segregate the test scripts from the locators. In case of changes in the webelement properties, test scripts need not be modified only the locators undergo change.Usage of Behavior Driven Development framework. This allows the participation of all members in the agile team to participate in product development.Encourage testing to start from very early phases and in regular ... Read More

Get HTML Source of WebElement in Selenium WebDriver using Python.

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:27:13

11K+ Views

We can get html source of a webelement with Selenium webdriver.We can get the innerHTML attribute to get the source of the web element.The innerHTML is an attribute of a webelement which is equal to the text that is present between the starting and ending tag. The get_attribute method is used for this and innerHTML is passed as an argument to the method.Syntaxs = element.get_attribute('innerHTML')We can obtain the html source of the webelement with the help of Javascript Executor. We shall utilize the execute_script method and pass arguments index.innerHTML and webelement whose html source is to be retrieved to the ... Read More

How do you click on an element which is hidden using Selenium WebDriver?

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:24:25

9K+ Views

We can click on an element which is hidden with Selenium webdriver. The hidden elements are the ones which are present in the DOM but not visible on the page. Mostly the hidden elements are defined by the CSS property style="display:none;". In case an element is a part of the form tag, it can be hidden by setting the attribute type to the value hidden.Selenium by default cannot handle hidden elements and throws ElementNotVisibleException while working with them. Javascript Executor is used to handle hidden elements on the page. Selenium runs the Javascript commands with the executeScript method. The commands ... Read More

How to navigate back to current page from Frame in selenium webdriver?

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:21:49

1K+ Views

We can navigate back to the current page from frame with 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 main browser driver. In order to access a frame element, the driver focus has to shift from the main browser window to the frame. To again focus back to the current page from frame, the method switchTo().defaultContent() is used.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; public class SwitchBackFrame{    public static ... Read More

How to use regex in selenium locators?

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:19:58

5K+ Views

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

How to verify an attribute is present in an element using Selenium WebDriver?

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:17:26

3K+ Views

We can verify if an attribute is present in an element with Selenium webdriver. This is achieved with the help of the getAttribute method. In an html document, each element is identified with its tagname along with the element attributes with their values. To get an attribute value, we have to pass the element attribute as an argument to the getAttribute method.Let us see the html code of an element and obtain the value of its src attribute. The value of its src attribute shall be /about/images/logo.png.ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class AttributeVal{ ... Read More

Selenium and Python to find elements and text?

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:15:25

580 Views

We can find elements and its text with Selenium webdriver. First of all we have to identify the element with the help of any of the locators like id, classname, css and so on. Then to obtain the text we have to take the help of the text method.Syntaxs = driver.find_element_by_css_selector("h4").textHere driver is the webdriver object. The method find_element_by_css_selector is used to identify the element with css locator type and the locator value is passed as an argument to the method. Finally the text method is used to obtain the text content of the element.Let us look at the html of ... Read More

How can I close a specific window using Selenium WebDriver with Java?

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:13:15

2K+ Views

We can close a specific window with Selenium webdriver. The getWindowHandles and getWindowHandle methods can be used to handle child windows. The getWindowHandles method is used to store all the opened window handles in the Set data structure.The getWindowHandle method is used to store the window handle of the browser window in focus. We have to add import java.util.Set and import java.util.List statements to accommodate Set data structure in our code.By default, the driver object can only access the elements of the parent window. In order to switch its focus from the parent to the child window, we shall take ... Read More

How do I select elements inside an iframe with Xpath?

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:10:52

8K+ Views

We can select elements inside an iframe with xpath 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. Let us see the html code of a frame.Selenium by default has access to the parent browser driver. In order to access inside a frame, the driver focus has to shift from the main browser window to the frame. There are more than one methods to shift focus to frames −switchTo().frame(id) - The id or name of frame is passed as an ... Read More

How to set “value” to input web element using selenium?

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:08:32

11K+ Views

We can set value to input webelement using Selenium webdriver. We can take the help of the sendKeys method to enter text to the input field. The value to be entered is passed as an argument to the method.Syntaxdriver.findElement(By.id("txtSearchText")).sendKeys("Selenium");We can also perform web operations like entering text to the edit box with Javascript Executor in Selenium. We shall use the executeScript method and pass argument index.value='' and webelement as arguments to the method.SyntaxWebElement i = driver.findElement(By.id("id")); JavascriptExecutor j = (JavascriptExecutor)driver; j.executeScript("arguments[0].value='Selenium';", i);ExampleCode Implementationimport org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.By; import java.util.concurrent.TimeUnit; public class SetValue{    public static void main(String[] ... Read More

Advertisements