Find Element Containing Specific Text in Selenium WebDriver with Python

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:04:36

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

Open Link in New Tab of Chrome Browser using Selenium WebDriver

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:03:34

2K+ Views

We can open a link in the new tab of Chrome browser using Selenium webdriver using the methods Keys.chord and sendKeys. The method Keys.chord is used to send multiple keys simultaneously as parameters.To open a new tab, the Keys.CONTROL and Keys.ENTER are passed as parameters to the Keys.chord. Finally, the Keys.chord is passed as a parameter to the sendKeys.Let us click on the Jobs links in a new tab, highlighted in the below image −SyntaxString l = Keys.chord(Keys.CONTROL, Keys.ENTER); driver.findElement(By.xpath ("//a[@title='Job @ Tutorials Point']")).sendKeys(l);Exampleimport 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.Keys; public class ElementLocator{    public ... Read More

Find Element and FindElements in Selenium

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:02:47

2K+ Views

The methods findElement and findElements are used to identify elements on the webpage. Both these methods can be used with locators like id, css, class, name, xpath, css, link text, tagname and partial link text.The method findElement is used to identify an element which matches with the locator (used with By object) passed as a parameter to that method. If there is no matching element, then NoSuchElementException is thrown.The method findElements is used to identify a list of elements which matches with the locator (used with By object) passed as a parameter to that method. If there is no matching ... Read More

Find Element Using Attribute and Tag Name in Selenium

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:02:02

1K+ Views

We can find an element using the element tag name with Selenium webdriver with the help of locator tagname. To locate an element with tagname, we have to use the By.tagName method.In the html code, a tagname is usually enclosed by , for example, an anchor tag represents links on the page. An input tag represents text boxes, checkboxes or radio buttons. Let us look at the html code of an element and try to identify it with its tagname −In the above image, the text – You are browsing the best resources for has the h4 tag.SyntaxWebElement e ... Read More

ChromeDriver Executable Does Not Exist - IllegalStateException in Java Selenium

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:01:42

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

Find Elements Using Selenium WebDriver

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:01:10

519 Views

We can find elements using Selenium webdriver with the help of the findElements method. This can be applied to the locators like id, class, name, link text, partial link text, css, xpath and tagname.The findElements method returns a list of elements which match with the locator (with the By object) passed as a parameter to the method. To count the number of elements returned by the list, the method size is used. If there are no matching elements, an empty list is returned.The below image shows the list of methods available with findElements.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; ... Read More

Convert JSON to CSV File Using PowerShell

Chirag Nagrekar
Updated on 06-Apr-2021 08:00:52

4K+ Views

To convert the JSON to the CSV format we need to first use the ConvertFrom-JSON command. For example, we have already JSON file present with us at the C:\temp\VMinfo.JSON location. We will first import this file and then convert it to CSV as shown below.Get-Content C:\Temp\VMInfo.json | ConvertFrom-Json | Export-Csv C:\Temp\vminfo.csv -NoTypeInformationSuppose you have cmdlet that produces output in the hash table format as shown below.PS C:\> Get-AzVM -VMName TestMachine2k16 | Select -ExpandProperty Tags Key             Value ---             ----- For             Ansible Patching_Day ... Read More

Change Azure Tag Value Using PowerShell

Chirag Nagrekar
Updated on 06-Apr-2021 07:59:15

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

Get Applied Azure Resource Tags Using PowerShell

Chirag Nagrekar
Updated on 06-Apr-2021 07:57:16

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

Apply a Tag to Azure Resource Group Using PowerShell

Chirag Nagrekar
Updated on 06-Apr-2021 07:54:56

674 Views

Like Azure VM, we can apply the azure tags to the resource group or any other resources. The tagging works on the resource ID and in azure, all the resources come with the resource ID property.To apply the tag to the azure resource group, we first need to use get the resource group details to use its resource ID. The below code shows that how we can apply the new tag to the azure resource group.ExamplePS C:\> $rg = Get-AzResourceGroup -Name AnsibleTestRG PS C:\> $tag = @{Owner='Chirag'; CostCenter='USFinance'} PS C:\> New-AZTag -ResourceId $rg.ResourceId -Tag $tag -VerboseOutput

Advertisements