课程: Test Automation with Selenium WebDriver for Java
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Clickable elements
- [Instructor] Let's explore how to use WebDriver to click web elements such as buttons and links. This button doesn't have an ID, but we can use an XPath query composed of the element's type and inner text. To find the element, we'll say: driver.findElement, and then we'll say By.xpath. In the XPath, we'll use two forward slashes to start from the root. We'll specify the element's type as button, and we'll say call the text() function on that, and make sure that it returns "Submit". Then from here we can say .click(). We can use this same technique to click this link. The extra spacing here could prove problematic, but we can take care of that within an XPath selector. So we'll say driver.findElement By.xpath, and we'll start with the a element, and we'll call a function named normalize-space, and we'll call text() inside of that, and then we'll set this equal to the text of the link, which was "Return to index". From here, we can call .click(), and that will click the link. In…