DjangoCon 2015

Automatizando la interacción con tu navegador y tus aplicaciones mediante Python

Al Sweigart  · 

Transcripción

Extracto de la transcripción automática del vídeo realizada por YouTube.

I know it's great to be back in Austin I actually grew up in Texas and I went to UT Austin so even though I lived for the last decade in San Francisco I'll take this off of a slightly controversial opinion I like programming there are several things

I like about programming most thing that it requires a keen attention to detail so much that I want to teach other people's programs so I wrote a programming book it's called automate the boring stuff at the pipeline and it's available under a

Creative Commons license so you can read it for free at automate the boring stuff comm and I really encourage you to use Creative Commons as the licenses available it has a lot of advantages but main advantage I found is that having it online I can use analytics

to look at what people are paying attention to and which chapters are the most read and so the chapters on web scraping and GUI automation are the most popular chapters in this book so that's what this presentation is about so you have about 10 minutes

before people start recording and so when we start writing programs that can go onto websites also kind of requires all this technical knowledge about networking protocols and connectivity in this next slide right here okay unfortunately though you don't

actually have to know any of that information there's a selenium all that will launch a browser that you can programmatically control so if you have to write automated tests for your web app and you don't want to just download the HTML one beautiful

scoop on it or some other person if she wants to run as it would for a user running olden JavaScript on the page and setting up all that state selenium is great you it's really simple to install just hit install selenium any figured out for the first time

I heard about this my companies QA department was oh well that sounds great but it all sounds really complicated it's actually really dead simple I can fit it into a 45 minute presentation along with the automation there's really only about half a

dozen things that you need to know and roll along this slide hey that worked so I mean it's not that complicated there's a whole bunch of bullet text go ahead and ignore that but using selenium excusable you import the module just and the other bathroom

you call this Firefox function and this will actually launch an instance of Firefox on your computer you will see the everything and that gives you a browser object you can call this get nothing by mutual website and then you can use CSS selectors to find

some particular skin element on that web page kind of like you know a link or check box and call the quick method and the present both quick and you can so long so that's a whole bunch of telling and I should be showing so I'm going to do something

that is incredibly ill-advised and that is a live demo yes all tapping out a power point and running idle anything can go wrong live demo okay so also I just wanted to show that it is possible to keep all of this but we selenium stuff inside your head at the

same time so let's go ahead and import this module so from important driver so first bit of weirdness about selenium that you should know is that you actually have to do this exact same syntax you have to type from selenium import webdriver you can't

just have import selenium or anything like that a weird little thing that's about this mean that you should be aware of so next let's go ahead and create that browser so Firefox works out right out of the package if you want to have Chrome or Safari

or something else you can there's a little bit of setup but this will actually go ahead and launch Firefox and you can see it up here on the screen so I'm gonna have this off to the side and we'll just call that get method to send it to a website

and I kind of wanted to plug my book some more so we'll just go to the waterborne stop calm and you can see now I have programmatic control I'm controlling the browser from a Python script so this is really nice that's the website and you know

if you're sitting up in automated tests you all have to go through and figure out what exactly your test should click on where you can expect applying that so let's just do that here you're going to have to get an element object so some HTML element

from that page like how long like when they were handing out words to use in method names I think this method was at the front of the line so yes I'll take them all so kind of verbose but it works and then you just end it in the CSS selector so if you

use CSS you might be familiar with this or if you used something like beautiful soup but it can be it's a selector is kind of like a regular expression from HTML it allows you to specify some particular parts of that HTML document or that web page and

you could learn all the syntax for that so you'd be able to write it yourself or you can cheat by using the browser to calculate that for you I'm gonna click on this introduction link so I'm gonna get the selector for that so I'll just right

[ ... ]

Nota: se han omitido las otras 2.539 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.