Debomita Bhattacharjee

Debomita Bhattacharjee

590 Articles Published

Articles by Debomita Bhattacharjee

Page 40 of 59

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

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 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

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

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 3K+ 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
Debomita Bhattacharjee
Updated on 26-Oct-2020 12K+ 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
Debomita Bhattacharjee
Updated on 26-Oct-2020 16K+ 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 locate element by partial id match in Selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 11K+ 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
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 868 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 944 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 use the gecko executable with Selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 26-Oct-2020 370 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
Showing 391–400 of 590 articles
« Prev 1 38 39 40 41 42 59 Next »
Advertisements