![]() Use the linkText locator method to find the link and perform click using click() methodĭriver.findElement(By.linkText("This is a link")).click() ĭriver.findElement(By.id("fname")).sendKeys("JavaTpoint") ĭriver.findElement(By.id("fname")).clear() String sampleText = driver.findElement(By.className("col-md-12")).getText() Use the class name of the div to locate it and then fetch text using getText() method Fetch the text "This is sample text." and print it on console WebDriver driver= new FirefoxDriver(capabilities) Initialize Gecko Driver using Desired Capabilities ClassĭesiredCapabilities capabilities = DesiredCapabilities.firefox() ĬtCapability("marionette",true) tProperty("","D:\\GeckoDriver\\geckodriver.exe" ) There are two methods to fetch a web page: Given below are some of the most commonly used Selenium commands in WebDriver: 1. The commands provided by Selenium WebDriver can be broadly classified in following categories: Now, we will discuss the various commands provided by WebDriver. If it is returning a value, then it must display the type of the value for e.g. If the void is mentioned after the method, it means, the method is returning no value. Methods can return a value or returning nothing (void). ParameterĪ parameter is an argument which is passed to a method to perform some specific operation. To access any method of any class, we need to create an object of class and then all the public methods will appear for the object. Let us consider an example form the suggestions displayed by Eclipse to understand the syntax of the methods provided by WebDriver. ![]() ![]() It will show you all of the possible methods provided by WebDriver. Therefore, one possible way to view the methods provided by WebDriver is to open the Eclipse IDE loaded with Selenium Webdriver jar files, create a driver object for WebDriver and press the dot key. Till now, we have successfully created our first test script in Selenium WebDriver. ![]() Now, the question arises is that how can we access methods provided by WebDriver. You can also refer to our Java OOPs concepts section provided in the Java Tutorial. Note: A java method is a collection of statements that are grouped together to perform a specific operation.īefore getting into the details of commands provided by Selenium WebDriver, we insist you to go through the Java OOPs (Object-Oriented Programming) concepts in java programming language. Since we are using Selenium WebDriver with Java, commands are simply methods written in Java language. In Selenium WebDriver, we have an entirely different set of commands for performing different operations. Next → ← prev Selenium WebDriver- CommandsĪs we have discussed earlier in the IDE section, Selenium commands are the set of commands that are used to run our Selenium tests. ![]()
0 Comments
Leave a Reply. |