Python Selenium Tutorial - Automate Websites and Create Bots

Sdílet
Vložit
  • čas přidán 21. 07. 2024
  • Today i'm going to show you everything you need to know about Selenium so you can get up-and-running as fast as possible. Selenium is a simple yet powerful tool used to create bots, web automation, & more using Python. You will be able to follow along regardless of your current skill level in Python programming.
    Get $15 of free credit when you create a new BrightData account: brdta.com/techwithtim-selenium
    🎓 Premium Courses 🎓
    🏢 CourseCareers - techwithtim.net/dev
    🔗 BlockchainExpert - algoexpert.io/blockchain (use code “tim”)
    💻 ProgrammingExpert - programmingexpert.io/tim (use code “tim”)
    🎓 Free Courses 🎓
    📚 Introduction To Software Development: techwithtim.net/dev
    🎞 Video Resources 🎞
    Code in this video: github.com/techwithtim/Seleni...
    Download ChromeDriver: sites.google.com/chromium.org...
    Cookie Clickers Website: orteil.dashnet.org/cookieclic...
    Install Pygame (Mac): • How to Install Pygame ...
    Install Pygame (Windows): • How to Install Pygame ...
    ⏳ Timestamps ⏳
    00:00 | Introduction
    01:41 | Installing Selenium
    07:50 | Locating & interacting With Elements
    10:02 | Potential Problems & Getting Blocked
    12:35 | Brightdata Unblocking Solution
    17:45 | Clicking Links & Navigating Pages
    23:15 | Automating Cookie Clickers - Sample Project
    🔗 Socials 🔗
    📸 Instagram - / tech_with_tim
    🐦 Twitter - / techwithtimm
    💬 Discord - / discord
    🤝 LinkedIn - / tim-ruscica-82631b179
    🌐 Website - techwithtim.net
    💾 GitHub - github.com/techwithtim
    🔗 Support 🔗
    👕 Merch - teespring.com/stores/tech-wit...
    💵 Donations - www.paypal.com/donate?hosted_...
    🙏 Patreon - / techwithtim
    🔖 Tags 🔖
    - How to use Selenium
    - Selenium python tutorial
    - Python selenium web scraping
    Hashtags
    #python
    #techwithtim
    #selenium

Komentáře • 180

  • @MohammedSalah2405
    @MohammedSalah2405 Před měsícem +16

    What makes me feel suspecious about the comments is that I hardly find anyone facing an issue, while if you're following the same steps you WILL definitely face issues with the code. But the comments section is full of angels

    • @zen1818
      @zen1818 Před měsícem

      I'm sure they are not real people

    • @CalmCabezonFish-nb6qt
      @CalmCabezonFish-nb6qt Před 21 dnem +1

      For your kind information, most people watch this to just have an overview of how it works. For development docs are available officially

  • @thembekilethembekile5839
    @thembekilethembekile5839 Před 4 měsíci +18

    It’s been years now and you still manage to release content when I need it the most. You just clutch dude ❤

  • @HebbenBeeld
    @HebbenBeeld Před 7 měsíci +36

    @28:50 If you want to go straight to the html element in inspection (here: the number of cookies), click on the arrow in the dotted square at the top left corner of the inspection window (it'll turn blue) and then click on the element on the webpage you want to find in the html. The inspection window will then take you straight to the html where the element is at.
    Having said that: great video!

  • @dfsed1057
    @dfsed1057 Před 7 měsíci +16

    Love your tutorials. I use xpath quite often when trying to find what to click on. In chrome, when you right click and inspect an element, it brings up the page source. Then if you right click the item that you are looking for, you can copy the xpath and paste it in your program as well.

  • @spazztik
    @spazztik Před 5 měsíci +13

    Been trying to figure out this for the last 2 days and could only find outdated and irrelevant videos. This video was really what i needed and even more. Props to you bro!

    • @jeeadvanced4719
      @jeeadvanced4719 Před 5 měsíci

      Bro what you trying automate?

    • @AshokanandChaudhary786
      @AshokanandChaudhary786 Před 4 měsíci

      Have you found more videos about the slenium?

    • @cbacca2999
      @cbacca2999 Před měsícem

      When I search YT or Google I always set my search to find stuff in the last year only.

  • @Ohiostategenerationx
    @Ohiostategenerationx Před 3 měsíci

    Great tutorial. As soon as I get python down pat I am going to watch this video several times because I have lots of sites I could automate.

  • @adesinapsalmlord7305
    @adesinapsalmlord7305 Před 7 měsíci +5

    I really love Tim tutorial for it conciseness and Simplicity
    Thanks for always serving us the best

  • @luisemilioogando
    @luisemilioogando Před 7 měsíci +1

    Great one, this is what i'm looking for, Automation, web scraping, bots, pytho automation, Qa automation.. Thank you so much. You are amazing.

  • @luisfcocontreras
    @luisfcocontreras Před 7 měsíci +8

    You should do an updated selenium series 🔥 would love that, some automation testing for things like SDET or QA

  • @MaxTheFireCat
    @MaxTheFireCat Před 7 měsíci +1

    I feel nostalgic, I remember watching your selenium series a few years ago

  • @EzraKoenigsberg-hn9pk
    @EzraKoenigsberg-hn9pk Před 2 měsíci

    Great video! Been looking for something that explains this process for a while.

  • @fernandomartino4708
    @fernandomartino4708 Před 7 měsíci +2

    Hi, Tim. Wouldn't be easier to use webdriver_manager library where it gets the last version of the driver to match the browser you have installed? because everytime you have a version upload you have to download it and retest this?

  • @seomaster7171
    @seomaster7171 Před měsícem

    Спасибо за подробный разбор, новая связка на отлично. Два круга, все сработало!

  • @bennikllr5509
    @bennikllr5509 Před 7 měsíci

    thanks, wanted to do this yesterday and kinda messed it up. (the old videos to selenium and the new driver) now everything works fine

  • @alexurrutia6495
    @alexurrutia6495 Před 6 měsíci

    Your tutorials are clutch man, thank you for all the knowledge!

  • @jocois
    @jocois Před 5 měsíci +2

    Does anyone know how to have the browser open with the default account? Mine always opens without it and its an issue, especially with SSO.

  • @benasmaciulaitis3292
    @benasmaciulaitis3292 Před měsícem +2

    Somewhy, when I run the ''python main.py'' command in terminal, I don't get anything, chrome doesn't start, nothing happens, at all.

  • @artabra1019
    @artabra1019 Před 6 měsíci +3

    Thanks for your selenium tutorials I have made 20k$ earnings as freelancer web scraping in Upwork.

    • @Chettahsofiane
      @Chettahsofiane Před měsícem

      علمني معك اريد ان اربح معك 20 الف دولار اخي

  • @cristianionut9885
    @cristianionut9885 Před 7 měsíci

    Hello. I am a beginner and I use VSC as well. For some reasons, when I run the exactly same code you typed, it opens my chromedriver without accessing the link. Why is that?

  • @sixthsense844
    @sixthsense844 Před 7 měsíci

    More selenium tutorial please, keep up the great content

  • @alimihakeem841
    @alimihakeem841 Před 5 dny

    Thanks for this great content. I love the way you explained in details

  • @doug8487
    @doug8487 Před 4 měsíci +5

    Hopefully this helps someone, I was having issues around 28:24 and getting the following error: "Message: stale element reference: stale element not found".
    This seemed to be because the page would load after clicking the language?
    I added time.sleep(5) to the line before finding the cookie and it solved the error. I'm not sure why the WebDriverWait function wasn't working as intended though, I'm assuming it was finding the cookie after the language was pressed but due to the loading screen popping up, Selenium ended up losing the cookie and errored out?

  • @oluwatosinoseni5413
    @oluwatosinoseni5413 Před 7 měsíci

    Does selenium still need us to install the drivers, i thought its now installed with the selenium 4.10

  • @MelTrades
    @MelTrades Před 7 měsíci +2

    Hey Tim how do i fix it if chrome driver is 120.0.6099.62 but mine is 120.0.6099.63

  • @Hotshot24-7
    @Hotshot24-7 Před 14 dny

    What’s the point of creating the service object if when you create the driver object the browser still opens when running the code from the IDE?

  • @rudyruderabbit
    @rudyruderabbit Před 3 měsíci +1

    nothing is happening when i try run google. i dont see selenium on the top left as you have, but it was innstalled...im stuck

  • @py_world
    @py_world Před 4 měsíci

    I would like to do this with brave browser which is also based on chromium,
    chromium version my brave instance is 122 while the downloaded version of the chrome driver is 123, I am unable to get driver version 122 nor am I able to update the brave browser. (win64)

  • @alexurrutia6495
    @alexurrutia6495 Před 6 měsíci +1

    I know that this may be asking for a lot, but could you make a tutorial on how to run parallel testing with selenium and pytest? Or whichever other tools you think are better for running multiple test cases at once?

  • @user-wu4ip7mp3z
    @user-wu4ip7mp3z Před 2 měsíci

    Just a question, instead of waiting for 5seconds for the elements to exist. Can you implement some kind of a loop to keep searching for the element until they do exist?
    Would this best be done with a while loop, and what would it look like?

  • @Dominichii7
    @Dominichii7 Před měsícem

    Do I have to update the chrome driver every time Google updates actual Chrome?

  • @garrettsmith315
    @garrettsmith315 Před 7 měsíci

    This is excellent, love everything about this!

  • @carlitosvh91
    @carlitosvh91 Před 7 měsíci

    This was very helpful. Thank you very much.

  • @top3model
    @top3model Před 6 měsíci +1

    hi Im getting this error when trying to install chrome driver,
    Google-Edge-Cache: forbidden
    Error: 7
    please help me with it

  • @FlockofSmeagles
    @FlockofSmeagles Před 4 měsíci

    I'm wanting to run a bot for an agency that my wife works for. Urgent shifts pop up fairly often. But, from what I suspect. Someone else is running a bot and snapping them up before she can get to them. I'd like to combat that, but there's no way to be sure. What I'm wanting to know is if there any way to detect whether or not the agency can detect bot activity. Since her ID is connected to the account. I won't be able to just spoof my IP.
    Any help would be appreciated.

  • @chetanpatil2473
    @chetanpatil2473 Před 6 měsíci

    hey some one help me i try to make my router restart using this libarary but it wont work it stuck and show error while confirmation windos not popup and i try everything but it wont work why ?/ any soluction for this

  • @shawntiaw
    @shawntiaw Před 4 měsíci

    Hi Tech With Tim, i follow your tutorial and it works super fine! learn some basic from you but i encounter some issue. how to use if and else if i want a button to be clickable. if not clickable then auto refresh until it become clickable?

  • @memeshouse8621
    @memeshouse8621 Před 5 měsíci +1

    when try to login into gmail it says "could nkt sing in , browser not secure" how to solved it?

  • @ColeHillyer
    @ColeHillyer Před měsícem

    Excellent lesson thanks for explaining each step

  • @oblivion7300
    @oblivion7300 Před 6 měsíci

    can someone tell me where he got the class gLFyf because i didnt see it

  • @georgekamakia7591
    @georgekamakia7591 Před 7 měsíci +1

    great!!, thanks for the tutorial just what i needed

  • @johnmantzanis1213
    @johnmantzanis1213 Před 3 měsíci

    what if the ID and class names are changing every time you log in to the website?

  • @sajidghanchi7591
    @sajidghanchi7591 Před 2 měsíci

    Hey can someone please help me I am desperately looking to resolve this issue. I want to perform the same task but in my regular chrome browser instead of testing browser. Will it be possible? If yes then how?

  • @AsuGhimire
    @AsuGhimire Před 7 měsíci +3

    DUDE I NEEDED THIS AND YOU JUS UPLOADED IT XD

  • @jaouadbenji7088
    @jaouadbenji7088 Před 5 dny

    Help : when i try to click on a element the browser just closed and the programme stops

  • @user-ps2zr5lh8q
    @user-ps2zr5lh8q Před 5 měsíci +4

    Is no one else getting ElementNotInteractableException: Message: element not interactable?

  • @BikerBoyz7
    @BikerBoyz7 Před 26 dny

    Nicely explained thanks Tim

  • @vascomarques2380
    @vascomarques2380 Před 7 měsíci +2

    LETS GO, UPDATED VIDEOOO

  • @phaedrus2633
    @phaedrus2633 Před 7 měsíci +7

    You go way too fast for this 65-year-old brain, but I understand, a slower pace would be boring for young programmers. But for the first time, I have a handle about the concepts of web scraping. You are using the Selenium Python library to bot web surfing. Too cool!

    • @Alien-by3gb
      @Alien-by3gb Před 17 dny

      If u 65 why u coding?

    • @phaedrus2633
      @phaedrus2633 Před 16 dny

      @@Alien-by3gb It's a hobby of mine, ever since PCs hit the market. I remember when Apple IIs were the rage. I've been messing around with programming ever since.

  • @REALANSHUMAN
    @REALANSHUMAN Před 3 měsíci

    hello sir , i have no experience of coding . how can i learn to make automation bots or integrating api (i dont know what this is but it pays good on upwork ) ? how long do i need to learn it ? I need to come up with money by the end of july for my moms surgery

  • @jaschyns
    @jaschyns Před 4 měsíci +1

    I dont know where my selenium folder is man, i installed it through Pycharm.. dont know the default location.

  • @itstechshow7747
    @itstechshow7747 Před 7 měsíci +1

    You are a genius 🔥
    Your effort is remarkable ❤

  • @parsakei9006
    @parsakei9006 Před 3 měsíci

    Great tutorial sir, thank you.

  • @SatoOnAir
    @SatoOnAir Před 22 hodinami

    Guys why is the "stale element not found" error automatically fixed itself? I meet this bug muptile times and dont know why it can fix itself everytime i rerun the program

  • @FatihMumtaz-tt5to
    @FatihMumtaz-tt5to Před 24 dny

    if i have do it and nothing changes , what's wrong??? its not opened the chrome.....

  • @jdoublea2023
    @jdoublea2023 Před 3 měsíci

    Just wondering if anyone else has been trying to get past the collect data popup that appears when you directly open google using this method I cant interact with the search bar

  • @mubeenahmed5622
    @mubeenahmed5622 Před 25 dny

    is it possible to make a robot that monitor a website name BLS international visa embacy and robot notify me when appointment date are available???

  • @kayoutube690
    @kayoutube690 Před měsícem

    Is this working if the app is saml integrated??

  • @bisyrim1030
    @bisyrim1030 Před 7 měsíci

    also you can use driver.implicity_wait(10) instead of time.sleep(10)

  • @yassinehsouna5425
    @yassinehsouna5425 Před 5 měsíci +1

    i cant find the same version of the webdriver

  • @samurai317
    @samurai317 Před 7 měsíci

    Thank you so much for this.

  • @MrIncredible-mu5ec
    @MrIncredible-mu5ec Před 7 měsíci +39

    One question still remains: how to upload Selenium to a remote server and run it? For me, it's #1 reason why I try to avoid using Selenium.

    • @architech5940
      @architech5940 Před 7 měsíci +10

      Create an API for your selenium script and host it on a linode instance. There are tutorials for both.

    • @moumnalmunawy1806
      @moumnalmunawy1806 Před 7 měsíci +2

      So what do you use?

    • @gustavojuantorena
      @gustavojuantorena Před 7 měsíci

      You can use a docker container. There is containers with selenium already installed.

    • @brentfiegle9761
      @brentfiegle9761 Před 7 měsíci

      Look at AWS CloudWatch Synthetics. It can use selenium and save the screenshots, run on a schedule and alert you if the tests start failing.

    • @ikennamanagwu9646
      @ikennamanagwu9646 Před 7 měsíci +1

      Using a Linux server is doable but much more complex

  • @repairstudio4940
    @repairstudio4940 Před 7 měsíci

    Selenium = fun with Tim 🎉

  • @RohxnYadav
    @RohxnYadav Před 4 měsíci +1

    Fucking Great Video My Man, I have been getting errors everytime when i try to get the selenium working...
    after watching this video i solved my problem and its workingggg.

  • @mahapeyuw5946
    @mahapeyuw5946 Před 5 měsíci +2

    service=service didn't run. It gave me a traceback error.

  • @noobCoder7
    @noobCoder7 Před 5 měsíci

    how to handle if div is used as textfield

  • @makobobinzers
    @makobobinzers Před 2 měsíci +2

    is there a free alternative to brightdata?

  • @weistrass
    @weistrass Před měsícem

    Can it run on background?

  • @goldcandles
    @goldcandles Před 2 měsíci

    Can i make option with bot doing order according to telegram channel

  • @Tortexxxx
    @Tortexxxx Před 6 dny

    How u disabled asking about cookies?

  • @richardsifeanyi6766
    @richardsifeanyi6766 Před 7 měsíci

    Thanks for sharing 🙏

  • @jabirmustafasulaiman5147
    @jabirmustafasulaiman5147 Před 7 měsíci

    Wonderful project❤

  • @fatimanoor2497
    @fatimanoor2497 Před 7 měsíci +1

    Thanks Tim bro😊😊😊

  • @hongzhisui
    @hongzhisui Před 6 měsíci

    Hi Tim, thanks so much for putting the tutorial out there. I noticed that when I typed in executable_path, it gave me an error message (unresolved reference) for some reason?

    • @doug8487
      @doug8487 Před 4 měsíci

      Did you put chromedriver.exe in the same folder as your .py file?

  • @joshuawiley6506
    @joshuawiley6506 Před 7 měsíci +1

    Hi there, I'm having a major issues with my paths, I've added the driver to the PATH, I've pinpointed it specifically using an exact path, and a local path...still, it doesn't find the chrome driver.
    Message: unknown error: cannot find Chrome binary
    Stacktrace:
    It's been plaguing me and stopping my progress on every tutorial....please help! Thanks!

  • @justgoto8
    @justgoto8 Před 4 měsíci

    one thing I'll add in here, you need to open the driver before selenium can actually use it. I was getting errors of selenium not being able to find the driver even though my route was correct. as soon as a double clicked on the driver file and opened it, selenium was able to open the browser. I use MAC

  • @esat0_090
    @esat0_090 Před 7 měsíci

    tim whats your vs code settings for syntax colors I've tried some methods but none of them was working for example (ctrl + K + T) can you make a video about that or if you already have one tag me please

  • @akrammohamed8374
    @akrammohamed8374 Před měsícem

    I LOVE YOU TECH WITH TIM

  • @ElParacletoPodcast
    @ElParacletoPodcast Před 6 měsíci +1

    Thanks, but my Mac mini won;t let me run that file!

  • @RIFADOR001
    @RIFADOR001 Před 7 měsíci +4

    I tried to use the chromedriver in mac but it says No such file or directory: 'chromedriver'
    I have the file in the same directory, it has the name of the file, I used os.system("ls -l") to verify that the file is in the folder where the program is running but it doesn't matter...
    Do you have any suggestion?

    • @hakouthegamer7978
      @hakouthegamer7978 Před 5 měsíci +1

      Hey i had the same issue on windows, there is a library called seleniumbase and it autodetects chrome version and gets you the right chromedriver, i used it and it works instantly

    • @yangsong6111
      @yangsong6111 Před 3 měsíci +1

      I tried the full path and it works.

    • @jm27925
      @jm27925 Před 2 měsíci

      @@hakouthegamer7978 thanks for this. this resolved the issue for me in seconds.

    • @dogukantaytuglu
      @dogukantaytuglu Před měsícem

      @@yangsong6111 thanks!

  • @alexicek011
    @alexicek011 Před 7 měsíci +1

    It doesn't work for me :( , after launching the browser I see info about accepting or rejecting cookies and I can't get to the search element .Error > selenium.common.exceptions.ElementNotInteractableException: message: element not interactable

    • @dfsed1057
      @dfsed1057 Před 7 měsíci +1

      this will happen when a popup window blocks the element that is trying to be clicked. i think he had the similar thing when the language popup occured for example.

  • @shreyaschavan7976
    @shreyaschavan7976 Před 7 měsíci +1

    can't we just use 'from selenium import * '?

  • @samson6707
    @samson6707 Před 5 měsíci

    not sure why you do this extra step of downloading a webdriver and including it with Service instead of just using webdriver Chrome without the service parameter

  • @rverm1000
    @rverm1000 Před 7 měsíci

    wow thats so cool. i can use that.

  • @VoidTailor
    @VoidTailor Před 7 měsíci

    great content!

  • @jakemcardle1936
    @jakemcardle1936 Před 2 měsíci

    I'm having an issue at 11.05 when google opens I get a pop-up asking to accept/decline cookies, because of this "the tech with tim" doesn't get inputted, instead the window with google closes immediately. Do you know how I can stop that pop-up from showing?

  • @Agnarr_Valhalla
    @Agnarr_Valhalla Před 4 měsíci +2

    What do i do if chroome cookies consent block me from doing anything ?

    • @Agnarr_Valhalla
      @Agnarr_Valhalla Před 4 měsíci

      Btw i solved it myself, u search by xpath instead of class. You input the declines button xpath and then also a time.sleep(2) so the cookies have time to load properly

  • @AaronRMG
    @AaronRMG Před 7 měsíci

    Thanks! I enjoyed learning Selenium. ALTHOUGH, can someone help with my issue? I did exactly what Tim instructed on one computer (ran perfectly), but after sending myself the code to do the same on another computer, I ran into an issue where Selenium states in the terminal that it's "unable to locate or obtain driver for chrome". The driver is the .exe and it's in the same folder.
    I'm currently trying to figure it out on this second computer but if someone has any tips, I'd appreciate it.

    • @AaronRMG
      @AaronRMG Před 7 měsíci +1

      The terminal points at this line:
      driver = webdriver.Chrome(service=service)

    • @AaronRMG
      @AaronRMG Před 7 měsíci +3

      I found a solution: to fix it, I made the path to chromedriver.exe an absolute path. I wonder why a relative path wouldn't work on this device?

  • @moisespereire9528
    @moisespereire9528 Před 7 měsíci

    Good afternoon, your video is very good and helped me a lot but I want to know how I make my vscode terminal the same as yours? How do I configure my Vscode terminal to look like yours?

    • @elmundoennumeros405
      @elmundoennumeros405 Před 6 měsíci +1

      It's standard, you can check your python interpreter (down right)

    • @moisespereire9528
      @moisespereire9528 Před 6 měsíci


      Hello, sorry, but once again, it's not standard, my friend, your terminal has tabs and these tabs are not standard, how do I make my terminal the same as yours with tabs, what configuration did you do? Is there a video or document showing how to do this?

  • @MdRihab-ob5zk
    @MdRihab-ob5zk Před 4 měsíci

    Thanks Brother

  • @AmitojGamerBoy
    @AmitojGamerBoy Před 7 měsíci +1

    Which vs code theme do u use?

  • @rajagam5325
    @rajagam5325 Před měsícem +1

    thank you

  • @ZoonCodes-er1rb
    @ZoonCodes-er1rb Před 7 měsíci

    Thank you.

  • @nurdinmoha3505
    @nurdinmoha3505 Před 7 měsíci +1

    You are the BEST

  • @user-gl9ul5is6o
    @user-gl9ul5is6o Před 3 měsíci

    i love this guys

  • @PhunkyBob
    @PhunkyBob Před 7 měsíci

    Thank you for your videos! I love them.
    When I make a comment adding information based on my experience, it's always suppressed.
    What is the reason?
    For instance here I commented about a Python module helping with drivers installation.

    • @TechWithTim
      @TechWithTim  Před 7 měsíci +3

      Not sure if you add a lot of logs or code CZcams might think you’re a bot

  • @ima6683
    @ima6683 Před 6 měsíci

    I came to look for copper and I found gold. thanks for the video. you saved me. I hate pychar. I love vsc.

  • @DECODEDN
    @DECODEDN Před 2 měsíci

    It tells me elementnotinteractable

  • @user-ts5ku2il8b
    @user-ts5ku2il8b Před 2 měsíci

    thanks bro

  • @tilltheend6634
    @tilltheend6634 Před 7 měsíci +2

    how to disable the pop up page asking to refuse or accept the chart please

    • @tilltheend6634
      @tilltheend6634 Před 7 měsíci +1

      great video btw

    • @marcmuehleisen
      @marcmuehleisen Před 7 měsíci +1

      @@tilltheend6634 weird that tim still did not answer this as lots of ppl had this question already

    • @tilltheend6634
      @tilltheend6634 Před 7 měsíci

      @@marcmuehleisen i had the solution once with chatgpt

    • @marcmuehleisen
      @marcmuehleisen Před 7 měsíci

      What did you ask?

  • @bordignonjunior
    @bordignonjunior Před 7 měsíci

    AttributeError: 'WebDriver' object has no attribute 'get_element'
    why?