Articles on Trending Technologies

Technical articles with clear explanations and examples

How to loop through a menu list on a webpage using Selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 06-Apr-2021 8K+ Views

We can loop through a menu list on a webpage using Selenium webdriver.In a webpage, a list is represented by an ul tag and it consists of elements with li tag. Thus the li tag can be said as the child of ul.First, we have to identify the element with ul tag with any locator, then traverse through its li sub-elements with the help of a loop. Finally, use the method getText to obtain the text on the li elements.Let us try to identify the menu list on a webpage.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; import ...

Read More

How to get details of a webpage like url, title name, domain name etc using Javascript Executor in Selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 06-Apr-2021 1K+ Views

We can get details of a web page like url, title, domain name of webpage using JavaScript Executor in Selenium webdriver. Selenium can execute JavaScript commands with the help of the executeScript method. The command to be executed is passed as a parameter to that method.SyntaxTo get the page title, JavascriptExecutor j = (JavascriptExecutor) driver; String s = j.executeScript("return document.title;").toString();To get the current URL, String p = j.executeScript("return document.URL;").toString();To get the domain, String d = j.executeScript("return document.domain;").toString();Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class JavaScrptScope{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver", ...

Read More

How to get page source as it is in browser using selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 06-Apr-2021 12K+ Views

We can get page source as it is in browser using Selenium webdriver using the getPageSource method. It allows us to obtain the code of the page source.SyntaxString p = driver.getPageSource();We can also obtain the page source by identifying the body tag with the help offindElement method and then apply the getText method on it. The parameter By.tagName is passed as a parameter to the findElement method.SyntaxWebElement l= driver.findElement(By.tagName("body")); String p = l.getText();ExampleCode Implementation with getPageSourceimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class PgSrc{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver", ...

Read More

How to get the attribute value of a web element in Selenium (using Java or Python)?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 06-Apr-2021 3K+ Views

We can get the attribute value of a web element with Selenium webdriver using the method getAttribute and then pass the attribute for which we want to get the value as a parameter to that method.In an html code, an element is defined with attributes and its values in a key-value pair. Let try to get the class – heading, for the below element on the page −SyntaxWebElement t =driver.findElement(By.xpath("//li[text()='About Tutorialspoint']")); String s = t.getAttribute("class");Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class AttribtValue{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver", ...

Read More

What are the drawbacks of Selenium WebDriver?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 06-Apr-2021 610 Views

Some of the prominent drawbacks of Selenium are listed below −Has assistance for only web oriented applications.Time consuming to configure the environment unlike the paid tools like UFT.Has no features provided by Test Management tools like ALM or UFT.New characteristics introduced in Selenium, sometimes do not work as expected.Has no in-built test report generation. It has to be integrated with TestNG/JUnit for reports.Cannot be integrated with Test Management tools like ALM or UFT.Cannot be used for verifying images.Has no record and play feature, hence building a test script needs considerable time and effort.Cannot be used for verifying mobile applications. We ...

Read More

How to retrieve CSV file headers using PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 06-Apr-2021 6K+ Views

To retrieve the CSV file headers using PowerShell, we need to use the hidden property PSObject once we use to import the CSV file. We have a CSV file stored at the C:\temp\VMTags.csv and we need to retrieve its headers. The CSV file is as below.ABCDForPatching_DayApplicationOwnerAnsibleSundaySecretTagChiragImporting the CSV file, PS C:\> $csv = Import-Csv C:\Temp\VMTags.csv PS C:\> $csv For    Patching_Day Application Owner ---    ------------ ----------- ----- Ansible    Sunday    SecretTag ChiragExampleAccessing hidden property, PS C:\> $csv.psobjectOutputWe need to use Properties to get our values. We will get all the headers here.PS C:\> $csv.psobject.Properties | Select Name ...

Read More

How do I find an element that contains specific text in Selenium WebDriver (Python)?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 06-Apr-2021 6K+ Views

We can find an element that contains specific text with Selenium webdriver in Python using the xpath. This locator has functions that help to verify a specific text contained within an element.The function text() in xpath is used to locate a webelement depending on the text visible on the page. Another function contains() in xpath is used to locate a webelement with the sub-text of actual text visible on the page.Let us try to identify the element having the specific text - Privacy Policy.Syntaxl = driver.find_element_by_xpath("//a[text()='Privacy Policy']") m = driver.find_element_by_xpath("//a[contains(text(), 'Privacy')]")Examplefrom selenium import webdriver #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") ...

Read More

Java Selenium Chromedriver.exe Does not Exist IllegalStateException

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 06-Apr-2021 4K+ Views

An IllegalStateException is thrown while working with Chrome browser if the chromedriver.exe file path is set incorrectly in the method System.setProperty. Once this executable file is downloaded, it has to be extracted. Then its path should be copied and added as a parameter to the System.setProperty method.SyntaxSystem.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\DebomitaJava\chromedriver.exe")Also, it must be remembered that, for Windows, we have to specify the .exe extension while including the path. But it is not required for Mac or Ubuntu. We should also ensure that the chromedriver.exe file that we are using is compatible with the local Chrome browser version.Let us see an example for ...

Read More

How to change the Azure tag value using PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 06-Apr-2021 1K+ Views

To change the azure value using PowerShell we need to use the Update-AZTag command with the merge property.ExampleFor example, we have the Azure VM TestMachine2k16 and we have its tags as shown below.PS C:\> $vm = Get-AzVM -VMName TestMachine2k16 PS C:\> $vm | Select -ExpandProperty TagsOutputKey          Value ---          ----- Owner       Chirag For Ansible Patching_Day Sunday Application SecretTagWe need to change the Patching_Day from Sunday to Wednesday. We will use the below command.Example$tag = @{Patching_Day='Wednesday'} Update-AzTag -Tag $tag -ResourceId $vm.Id -Operation Merge -VerboseOutputName           Value ============ ...

Read More

How to get the applied azure resource tags using PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 06-Apr-2021 2K+ Views

To get all the applied tags to the Azure resources we need to use the Get-AZTag command and need to provide ResourceID to it. For example, We need to retrieve the Azure VM tags and we will use its resource ID.PS C:\> $vm = Get-AzVM -Name Testmachine2k16 PS C:\> Get-AzTag -ResourceId $vm.IdYou can see the output in the properties window. Another simple method is to use the Tags property for that particular cmdlet. For example, Get-AzVM, Get-AZResourceGroup, etc use the tag property for displaying the applied tags.PS C:\> Get-AzVM -VMName TestMachine2k16 | Select -ExpandProperty Tags Key         ...

Read More
Showing 49961–49970 of 61,297 articles
Advertisements