Found 871 Articles for Automation Testing

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

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:45:11

739 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

5K+ 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 close child browser window in Selenium WebDriver using Java?

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

5K+ Views

We can close the child browser window in 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 browser window currently active. To iterate over the window handles, the iterator method is used. We have to add import java.util.Set to accommodate Set and import java.util.List and import java.util.Iterator statements to accommodate iterator in our code.By default, the driver object can access the elements of the parent window. In order to switch its focus ... Read More

How to set Selenium Python WebDriver default timeout?

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:38:44

6K+ 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
Updated on 26-Oct-2020 06:37:18

236 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 select specified node within Xpath node sets by index with Selenium?

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:33:17

5K+ Views

We can select specific nodes within xpath node sets by index with Selenium webdriver. We can mention a specific node with the help of its index number enclosed in [].Let us have a look at the below html code for an element having children. The element with tagname ul has multiple child elements with tagname li. If we want to identify the second child of the parent having text as Software Quality management the xpath expression with node index shall be //ul[@class='list']li[2].The xpath expression to identify the second child of the parent element ul can also be created with the ... Read More

Accessing HTML source code using Python Selenium.

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:29:21

3K+ Views

We can access HTML source code with Selenium webdriver. We can take the help of the page_source method and print the value obtained from it in the console.Syntaxsrc = driver.page_sourceWe can also access the HTML source code with the help of Javascript commands in Selenium. We shall take the help of execute_script method and pass the command return document.body.innerHTML as a parameter to the method.Syntaxh = driver.execute_script("return document.body.innerHTML;")ExampleCode Implementation.from selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) driver.get("https://www.tutorialspoint.com/index.htm") # access HTML source code with page_source method s = driver.page_source print(s)Code Implementation with Javascript Executor.from selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) ... Read More

Reading JavaScript variables using Selenium WebDriver.

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:27:47

2K+ Views

We can read Javascript variables with Selenium webdriver. Selenium can run Javascript commands with the help of executeScript method. The Javascript command to be executed is passed as an argument to the method. Also we have to add the statement import org.openqa.selenium.JavascriptExecutor to work with Javascript.SyntaxJavascriptExecutor j = (JavascriptExecutor) driver; j.executeScript("return document.title")Let us obtain the browser title of the below page by reading the value from Javascript variable. The output should be About Careers at Tutorials Point – Tutorialspoint.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 org.openqa.selenium.JavascriptExecutor; public class JavascriptReadValue{    public static void main(String[] args) {   ... Read More

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

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:24:41

1K+ 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
Updated on 26-Oct-2020 06:22:49

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

Advertisements