There are some preconditions for an element to be clicked. Note: Most of the time we click on the links and it causes a new page to load, this method will attempt to wait until the page has loaded properly before handing over the execution to next statement. But If Click() causes a new page to be loaded via an event or is done by sending a native event for example through javascript, then the method will not wait for it to be loaded. IWebElement element = driver.FindElement(By.LinkText( "ToolsQA")) ĭriver.FindElement(By.LinkText( "ToolsQA")).Click() Void IWebElement.Click()- This simulates the clicking of any element. Accepts nothing as a parameter and returns nothing.Ĭlicking is perhaps the most common way of interacting with web elements like text elements, links, radio boxes and many more. IWebElement element = driver.FindElement(By.Id( "UserName")) ĭriver.FindElement(By.Id( "UserName")).SendKeys( "ToolsQA") This method works fine with text entry elements like INPUT and TEXTAREA elements. This method accepts string as a parameter and returns nothing. Void IWebElement.SendKeys(string text) - This simulate typing into an element, which may set its value. IWebElement element = driver.findElement(By.Id( "UserName")) ĭriver.FindElement(By.Id( "UserName")).Clear() Text entry elements are INPUT and TEXTAREA elements. This method has no effect on other elements. This method accepts nothing as a parameter and returns nothing. Void IWebElement.Clear() - If this element is a text entry element, this will clear the value. Clear() command, even if you have a link element still you get the option to choose Clear() command on it, which if you choose may result in some error or may not does anything. But all the actions will always populate against the any element irrespective of whether the action is valid on the IWebElement or not. One more thing to notice that IWebElement can be of any type, like it can be a Text, Link, Radio Button, Drop Down, WebTable or any HTML element. IWebElement element = driver.FindElement(By.Id("UserName")) Īnd now if you type element dot, Eclipse's intellisence will populate the complete list of actions just like the above image. So, to get the IWebElement object write the below statement: The same way FindElement command of IWebDriver returns IWebElement. As in the previous chapters, we learned that every method of the IWebDriver either returns something or return void( means return nothing). Īll interesting operations to do with interacting with a page will be performed through this IWebElement Interface.īefore going through each and every action of IWebElement, let's just understand that how we get an IWebElement object/element. All HTML documents consist of nested HTML elements. HTML elements can be nested ( elements can contain elements).
The HTML element is everything from the start tag to the end tag: My first HTML paragraph. HTML elements are written with a start tag, with an end tag, with the content in between: content HTML documents are made up by HTML elements. In this chapter, we will learn What is WebElement and the List of Actions can be performed on various WebElements. But before moving on to finding different WebElements, it better to cover that what all operations we can perform on a WebElement. This chapter is all about Selenium WebDriver WebElement Commands. Soon we will be identifying the different WebElement on webpages and performing various actions on it. So far in our Selenium Learning journey, we have done WebDriver Commands and Navigation Commands.