WEBVTT 1 00:00:00.240 --> 00:00:01.660 Hi guys and welcome back. 2 00:00:01.660 --> 00:00:05.150 In this video, we're gonna be pressing that search button. 3 00:00:05.150 --> 00:00:07.700 So, let's start with app.py. 4 00:00:07.700 --> 00:00:11.480 We're gonna do page.search_button.click. 5 00:00:11.480 --> 00:00:14.187 That's how you interact with something in Selenium 6 00:00:14.187 --> 00:00:16.870 and in this case it's gonna be that search button 7 00:00:16.870 --> 00:00:20.070 that doesn't exist on the quotes page yet 8 00:00:20.070 --> 00:00:23.150 and then we're gonna do print page.quotes. 9 00:00:23.150 --> 00:00:25.180 So, let's go over to the quotes page 10 00:00:25.180 --> 00:00:27.530 and add our search button. 11 00:00:27.530 --> 00:00:28.850 I'm just gonna add it down here 12 00:00:28.850 --> 00:00:30.170 underneath the tags dropdown. 13 00:00:30.170 --> 00:00:32.110 It's gonna be a property search_button 14 00:00:34.533 --> 00:00:35.366 and what this is gonna do 15 00:00:35.366 --> 00:00:39.930 is return self.browser.find_element_by_css_selector 16 00:00:40.770 --> 00:00:42.953 and that is gonna be the QuotesPageLocators.SEARCH_BUTTON. 17 00:00:46.030 --> 00:00:48.160 And that's it, you've got the button, 18 00:00:48.160 --> 00:00:49.490 you can click on it now, 19 00:00:49.490 --> 00:00:53.113 we can run app.py, Bob Marley. 20 00:00:54.170 --> 00:00:56.140 We're gonna type love 21 00:00:56.980 --> 00:00:59.243 and there you have your quote. 22 00:01:00.250 --> 00:01:01.610 And if you go back to the site, 23 00:01:01.610 --> 00:01:04.270 you'll see that this has actually worked. 24 00:01:04.270 --> 00:01:05.900 The button has been clicked 25 00:01:05.900 --> 00:01:10.180 and this is how you interact with websites using Selenium. 26 00:01:10.180 --> 00:01:13.550 As you can see, it's not all that complicated. 27 00:01:13.550 --> 00:01:15.770 You have to have a page model 28 00:01:15.770 --> 00:01:18.610 that reflects what the page contains 29 00:01:18.610 --> 00:01:19.970 and what it looks like 30 00:01:19.970 --> 00:01:22.850 so that you can then very easily just say okay, 31 00:01:22.850 --> 00:01:23.870 I wanna click this button, 32 00:01:23.870 --> 00:01:25.973 I wanna select this thing and so on. 33 00:01:27.300 --> 00:01:28.690 It is the app.py though 34 00:01:28.690 --> 00:01:31.410 that is starting to get a little bit more complicated 35 00:01:31.410 --> 00:01:33.710 just because it contains all the logic 36 00:01:33.710 --> 00:01:36.050 about how we're gonna interact with the page. 37 00:01:36.050 --> 00:01:38.210 We're gonna ask what author you want, 38 00:01:38.210 --> 00:01:39.520 then we're gonna select an author, 39 00:01:39.520 --> 00:01:41.130 then we're gonna get the available tags, 40 00:01:41.130 --> 00:01:42.140 then we're gonna print them 41 00:01:42.140 --> 00:01:43.870 and then we're gonna ask for which one you want 42 00:01:43.870 --> 00:01:45.153 and so on and so forth. 43 00:01:46.560 --> 00:01:48.930 We can make that a bit simpler 44 00:01:48.930 --> 00:01:51.640 by encapsulating some of this logic 45 00:01:51.640 --> 00:01:53.880 into the page as well. 46 00:01:53.880 --> 00:01:56.350 Remember that this page here 47 00:01:56.350 --> 00:02:00.470 doesn't only have to contain page elements. 48 00:02:00.470 --> 00:02:03.210 It can also contain page actions 49 00:02:03.210 --> 00:02:04.480 like selecting an author, 50 00:02:04.480 --> 00:02:07.520 getting available tags, or potentially performing 51 00:02:07.520 --> 00:02:09.780 the whole search flow. 52 00:02:09.780 --> 00:02:11.960 Let's go and do that in the next video. 53 00:02:11.960 --> 00:02:12.910 I'll see you there.