Found 719 Articles for Testing Tools

What does WebElement clear() Do to TextBoxes?

Debomita Bhattacharjee
Updated on 18-Sep-2020 12:02:29

2K+ Views

We can erase the contents from text boxes with Selenium webdriver. This is done with the clear() method. This method clears the edit box and also makes the field enabled.First of all we need to identify the element with help of any of the locators like id, class, name, xpath or css and then apply sendKeys() method to type some text inside it. Next we shall apply the clear() method on it. To check if the edit box got cleared, we shall use getAttribute() method and pass value parameter as an argument to the method. We shall get blank value ... Read More

How to get text from Selenium element WebElement object?

Debomita Bhattacharjee
Updated on 18-Sep-2020 11:58:38

7K+ Views

We can get text from a webelement with Selenium webdriver. The getText() methods obtains the innerText of an element. It fetches the text of an element which is visible along with its sub elements. It ignores the trailing and leading spaces.First of all we need to identify the element with help of any of the locators like id, class, name, xpath or css and then apply getText() method on it to get the text content of the element.Let us get the text of the element About Careers at Tutorials on the page−Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import ... Read More

How to use selenium to check if element contains specific class attribute?

Debomita Bhattacharjee
Updated on 18-Sep-2020 11:49:28

5K+ Views

We can check if an element contains a specific class attribute value. The getAttribute() method is used to get the value of the class attribute. We need to pass class as a parameter to the getAttribute() method.First of all we need to identify the element with help of any of the locators like id, class, name, xpath or css. Then obtain the class value of the attribute. Finally, we need to check if the class attribute contains a specific value.Let us take an element with the below html code having class attribute. The tp-logo is the value of the class ... Read More

How do I get a parent HTML Tag with Selenium WebDriver using Java?

Debomita Bhattacharjee
Updated on 18-Sep-2020 11:35:08

491 Views

We can get a parent HTML tag with Selenium webdriver. First of all we need to identify the child element with help of any of the locators like id, class, name, xpath or css. Then we have to identify the parent with the findElement(By.xpath()) method.We can identify the parent from the child, by localizing it with the child and then passing (parent::*) as a parameter to the findElement(By.xpath()). Next to get the tagname of the parent, we have to use the getTagName() method.Syntaxchild.findElement(By.xpath("parent::*"));Let us identify tagname of parent of child element li in below html code−The tagname of the parent ... Read More

How does Selenium WebDriver's isDisplayed() method work?

Debomita Bhattacharjee
Updated on 18-Sep-2020 11:14:57

1K+ Views

We can work with isDisplayed() method in Selenium webdriver. This method checks if a webelement is visible on the page. If it is visible, then the method returns a true value, else it returns false.First of all, we have to identify the element with any of the locators like id, class, name, xpath or css and then apply isDisplayed() method on it.Syntaxboolean s= driver.findElement(By.id("txt-bx")).isDisplayed();Let us check if the element About Careers at Tutorials Point is displayed on the page. Since it is available it shall return a true value.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; public ... Read More

How do I get current URL in Selenium Webdriver 2 Python?

Debomita Bhattacharjee
Updated on 18-Sep-2020 11:07:46

852 Views

We can get the current URL of a page with Selenium webdriver. The method current_url is available which obtains the present page URL and then we can print the result in the console.Syntaxs = driver.current_urlLet us find the URL of the page presently navigated and we shall get https://www.tutorialspoint.com/index.htm as the output. Examplefrom selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) driver.get("https://www.tutorialspoint.com/index.htm") #identify current URL with current_url l= driver.current_url print(Current URL is: " + l) driver.close() Output  Read More

How to get all descendants of an element using webdriver?

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:49:52

1K+ Views

We can get all descendants of an element with Selenium webdriver. First of all we need to identify the parent element with help of any of the locators like id, class, name, xpath or css. Then we have to identify the descendants with the findElements(By.xpath()) method.We can find the descendants from the parent element, by localizing it with the parent and then passing ( .//*) as a parameter to the findElements(By.xpath())Syntaxelement.findElements(By.xpath(".//*"))Let us identify the tagname of the descendants of ul element in below html code−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; public class DescendantElements{    public ... Read More

Get value of an input box using Selenium (Python)

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:41:33

10K+ Views

We can get the value of an input box with Selenium webdriver. The get_attribute() method is capable of obtaining the value we have entered in an input box. To get the value, we have to pass value as a parameter to the method.First of all, we have to identify the input box with the help of any of the locators like id, class, name, css or xpath. Then we have to type some values inside it with the send_keys() method.Let us consider the below input box where we shall enter some texts - Selenium Python and then fetch the value ... Read More

How to get attribute of element from Selenium?

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:36:56

8K+ Views

We can get the attribute of element in Selenium webdriver. The getAttribute() method is used to obtain the value of an attribute in an html document. In an html code, attribute and its value appear as a key value pair.Some of the commonly known html attributes are disabled, alt, id, href, style, title and src. The value of the attribute that we want to fetch is passed as an argument to the method.Let us consider an html code, for which we shall obtain the src attribute. The value of the src attribute should be /about/images/logo.png.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; ... Read More

How to get selected option using Selenium WebDriver with Java?

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:34:21

14K+ Views

We can get a selected option in a dropdown in Selenium webdriver. The method getFirstSelectedOption() returns the selected option in the dropdown. Once the option is fetched we can apply getText() method to fetch the text.Let us consider the below dropdown Continents get its selected item−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.support.ui.Select public class SelecedItem{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String u =" https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm"driver.get(u);       driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);       // identify element   ... Read More

Advertisements