We have done a survey of topics relating to using Selenium Webdriver. What next? Where can we turn for more information? This video will conclude the course by pointing you in the direction of further resources.
Even Moar Info
Working with multiple windows
driver.getAllWindowHandles()- Gets the window handle of all available windows
driver.getWindowHandle()- Gets the handle of the current window
driver.switchTo()- Switches between windows
Alerts and Popups
Alerts and Popups can be frustrating to deal with because they are not part of the web content that you may be interacting with when they appear. Learn more about popup dialogs
Working with IFrames
Iframes embed content in a way that is not directly accessible with the other web content. Webdriver provides a mechanism to switch into the IFrame
Use the ActionSequence API for when you need to do things that are not possible through the standard WebElement API.
Raise your hand if you think practice doesn't help you learn. 0:00 You over there with your hand up. 0:04 Sorry, you're wrong. 0:05 Of course practice will help you to cement these concepts that you've just picked up. 0:06 Now the good news is, 0:10 if you haven't caught on to this yet, you can use any website. 0:11 Sometimes, there's even sites made for testing. 0:15 In fact, I've included some in the teacher's notes for you to check out and 0:18 I thought we'd explore one real quick. 0:21 Let's get practicing. 0:23 In the teacher's notes, I've listed some sites specifically set up for 0:25 testing via automation. 0:28 One of my personal favorites is this one here, the PHP Travel site. 0:30 So it's called phptravels.com/demo. 0:34 And what's rad about this is they give you these different logins that you can use 0:38 and you can go through the whole back end admin or the whole supplier admin. 0:42 It's great and it's great for practice. 0:46 So let's go ahead and let's open this up. 0:49 I'm just gonna show you really quick this PHPTRAVELS site here and 0:50 I wanna click this Contact Us link. 0:54 So let's bring our terminal back up. 0:56 Here we go. 0:59 So here I'm gonna start up our REPL. 0:59 Just like we did in the past, we'll just work through this REPL. 1:02 So we'll import selenium, All right, 1:04 that selenium_webdriver is the package that we're using here, that we wanna use. 1:09 And then we're gonna grab our helper class, our so 1:15 popular By helper class is selenium.By. 1:19 We're just pulling this into the namespace so we can use it easier. 1:22 We'll build the driver. 1:25 And again this is where, we didn't really do this much but 1:27 we could get a different driver here if we wanted to. 1:29 But we're still just gonna use Chrome. 1:31 Cuz I know that that's working. 1:33 So forBrowser("chrome"). 1:34 And we're gonna call build on the builder pattern to setup all of our. 1:38 Now we've got a driver, so let's go get that site. 1:43 So it's driver.get, And we want ("http://www.phptravels, 1:46 I think unrelated to the programming language, .net. 1:52 So there we go. 2:00 Oops, I'm gonna close these other, what we got open here. 2:02 So we've got this site here. 2:06 We've got it open. 2:09 How rad is that? 2:10 So I wanna click that Contact Us link, and this is something that we hadn't done yet. 2:11 And I wanted to show this off cuz this is really cool. 2:14 So we're gonna say driver.findElement. 2:17 And what we want is we wanna just click something, that link there. 2:21 So this is such a common thing, we're gonna say By.linkText. 2:24 We're gonna click Contact Us, okay? 2:27 And we'll click it. 2:30 So now if we look here, we'll see that we moved to that page and 2:32 it says Contact Us now. 2:37 And so, we've navigated to a new page. 2:39 So, just like how I could click this back button here, 2:43 I can also click the back button here. 2:45 So driver, there's a method called navigate which gets you in there 2:48 to the navigator portion so that you can say, back. 2:52 Okay, so, let's get that site up. 2:56 Let's do a little half screen thing here. 2:58 So we'll say back. 3:04 All right, and so it goes back there and then of course you probably guessed, 3:07 you can go forward. 3:10 And if you wanted to, you can also go ahead and refresh the page. 3:13 So you can see that it comes up, cool. 3:17 And I wanna go and let's go back once more, so boom. 3:20 We're back here. 3:25 And if you wanted to get the current URL on a page, 3:27 you probably might have guessed this, it's getCurrentUrl. 3:32 And that returns a venable, like we're used to, so url and 3:38 we'll say console.log(url). 3:42 And this is kinda handy to make sure that, so it returns phptravels.net. 3:44 This is handy for when you're trying to do multiple page objects. 3:49 Before we only had a single page, but now there's more. 3:53 One thing that I like about this page a lot is when I mouse over these hotels 3:55 here, let's see if I can get my mouse on there, 3:59 see how they go a little bit darker? 4:02 See how nice that is? 4:04 What if I wanted to test that? 4:06 If I wanted to test, making sure that that darkness happened, right? 4:07 So, how could we pretend to hover over something? 4:12 Well, this is kind of an advanced thing, but let's do it. 4:15 Let's walk through this. 4:18 So what we would do is we would find this. 4:19 Let's get this first. 4:22 Right click and choose Inspect. 4:23 Okay, and this is just like we had before, 4:27 just a little bit different of a page, so let's see. 4:30 What do we got here, so there's an image and there's a class called row. 4:33 And it's inside of a thing called featured. 4:38 So we've got featured row. 4:42 So I'm gonna try to just see if I can get a hold of this featured row. 4:44 Let's see, let's see if we can do that, so let's see. 4:49 We'll say the first featured one, so we'll say firstFeatured, 4:54 and let's make sure that we're off of there. 4:58 All right, so let's do firstFeatured = driver.findElement And we want By.css. 5:03 Let's see, so we want the class of .featured, and inside of there, 5:12 there was a class of .row. 5:16 And because we're only using the singular find element, it will just do one. 5:18 Okay, cool. 5:22 And now, we can access some special actions for the driver. 5:23 Here, let's check this out in the doc really quick. 5:28 So if I'm on the web driver documentation, and 5:32 I look here at something called actions. 5:35 It will return an action sequence. 5:40 Okay? And here are an example of 5:42 some of the actions that you can do. 5:44 So you can click and you can drag and drop and 5:46 you can key down and you put them all together and then you call perform on it. 5:49 So if you wanted to do mouse down and the mouse over. 5:53 But what we're gonna do is we're gonna mouse move and 5:57 we're gonna move the mouse to right over the top of that location. 5:59 So let's do that. 6:03 So what we'll say is we'll say driver.actions. 6:05 We're gonna call that, mouseMove, and 6:08 we're gonna give it that element firstFeatured. 6:11 And then I'm gonna call perform, and you can chain a whole bunch of actions there. 6:17 So if I do that, boom, see how it went and 6:20 got highlighted as if we moved the mouse over there. 6:23 Okay, fine, one more thing for you to check out. 6:26 Sometimes you'll wanna wait for a certain thing on the page to load or 6:28 maybe you wanna wait for a certain amount of time. 6:32 In this case check out this documentation on until. 6:33 So if we come back to this, the top page here, 6:38 this until here is where we wanna look. 6:41 So you can say driver.weight, and then you can build this until this is available. 6:44 Then send the keys, right? 6:51 Okay, fine. 6:53 One more thing that I wanna show you before you start practicing. 6:54 If you come in here on any of these elements, and you choose inspect. 6:58 Let's get this a little bit, a little over zealous there. 7:04 Let's say I wanted to get a hold of this div right here, this clear fix div. 7:10 I can come in here and I can choose Copy and 7:14 then I can choose Copy Selector and that will give me the CSS, right? 7:17 So that will give me the CSS that I want. 7:23 Look at that, that's kind of little bit crazy CSS, but 7:25 hey, that's will get us there. 7:27 Or, I could also copy the XPath. 7:30 And that will help you find and narrow it down. 7:35 For sure, that's what selected it. 7:39 I don't think you'd ever actually write this because it's not 7:40 exactly what you want, but this will help you get there. 7:43 It's one way to copy there. 7:45 Okay, so I want you to have fun and keep practicing cuz you are doing great. 7:47
You need to sign up for Treehouse in order to download course files.Sign up