Found 719 Articles for Testing Tools

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

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

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

610 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

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

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

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

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

Advertisements