Python Selenium Tutorial #2 - Locating Elements From HTML

Sdílet
Vložit
  • čas přidán 27. 04. 2020
  • In this python selenium tutorial I cover how to locate elements from a webpage. This will show you how to find elements from a selenium script using their ID, class name, name and other features. In this video we use selenium to search for something on a website then list out all of the search results.
    Selenium Documentation: selenium-python.readthedocs.io/
    Playlist: • Python Selenium Tutori...
    Subscribe to my second CZcams channel for weekly podcasts: / @timeoutwithtim
    ◾◾◾◾◾
    💻 Enroll in The Fundamentals of Programming w/ Python
    tech-with-tim.teachable.com/p...
    📸 Instagram: / tech_with_tim
    🌎 Website techwithtim.net
    📱 Twitter: / techwithtimm
    ⭐ Discord: / discord
    📝 LinkedIn: / tim-ruscica-82631b179
    📂 GitHub: github.com/techwithtim
    🔊 Podcast: anchor.fm/tech-with-tim
    💵 One-Time Donations: www.paypal.com/donate/?token=...
    💰 Patreon: / techwithtim
    ◾◾◾◾◾◾
    ⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡
    ⭐ Tags ⭐
    - Tech With Tim
    - Python Tutorials
    - Selenium Tutorial
    - Selenium Python
    - Locating Elements Selenium
    - Find Elements Selenium
    ⭐ Hashtags ⭐
    #python #selenium #webscraping

Komentáře • 579

  • @longdidier
    @longdidier Před 2 lety +529

    Great tutorial!
    for anyone following on 2022, the method find_element_by_class_name was deprecated, gotta use find_element(by=By.CLASS_NAME, value="element to look for")

    • @utku5713
      @utku5713 Před 2 lety +1

      oh thanks :)

    • @indicgamer2907
      @indicgamer2907 Před 2 lety +3

      man finding elements by class is returning the nosuchelement exception no matter how much i try

    • @januszkonarski1274
      @januszkonarski1274 Před 2 lety +1

      @@indicgamer2907 Try this: article.find_element(by=By.CSS_SELECTOR, value="div.entry-summary")

    • @adthn
      @adthn Před 2 lety +11

      im getting an "unresolved reference" for that "By" in "By.CLASS_NAME"

    • @rushilkulkarni7206
      @rushilkulkarni7206 Před 2 lety +3

      @@adthn WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='search_query']"))).send_keys("youtube test")
      driver.find_element_by_xpath("//button[@id='search-icon-legacy']/yt-icon").click() try this

  • @rustams7502
    @rustams7502 Před 3 lety +175

    How is this FREE CONTENT so much better than the course I'm following on Udemy or any tutorial I've seen on selenium out there? The answer: Tim is an outrageously excellent communicator, an aberration

    • @tigron1530
      @tigron1530 Před 2 lety

      He doesnt has to make this content paid since he wins money from visits..

    • @kshau_
      @kshau_ Před 2 lety +2

      every coding tutorial i see, people are just criticizing udemy lol

    • @xilllllix
      @xilllllix Před 2 lety +1

      ​@@kshau_ it's bec the quality is poor compared with the price of the course

    • @shabba194
      @shabba194 Před 2 lety

      Which course are you taking?

    • @sidneyw.mathiasdeoliveira8621
      @sidneyw.mathiasdeoliveira8621 Před 2 lety

      Ansewer: free lessons are not worried of being super complete and well explained

  • @loznero6297
    @loznero6297 Před 4 lety +323

    You don't even know how useful these tutorials are... I've tried so many times to learn selenium, but there's no proper tutorials out there... until now!

    • @markdillon9588
      @markdillon9588 Před 4 lety +3

      Agreed ! And even less with python and selenium 👍

    • @johanjim4940
      @johanjim4940 Před 4 lety +3

      ya same very few tutorial on selenium i wanted to learn selenium 2 months back but due to less tutorials i dropped it but now i am learning from Tim.

    • @thomasalberto613
      @thomasalberto613 Před 4 lety +7

      This channel is simply fucking great

    • @vasanthbalaji1528
      @vasanthbalaji1528 Před 4 lety +2

      Check out in Udemy i have created a f/w using python and selenium

    • @janicejose5809
      @janicejose5809 Před 4 lety +2

      so hell true i was struggling trying to learn selenium until i found this channel

  • @MahaKhanMK
    @MahaKhanMK Před 4 lety +8

    These tutorials are exceptional so clear and precise. Thank you Tim! I need to make an entire project and submit it by the end of May and this tutorial is helping me understand things tremendously! Please if you can finish the entire series within the initial weeks of May. And keep being awesome. Much Love.

  • @chasemedsker
    @chasemedsker Před 4 lety +1

    You teach better than any teacher I have ever seen. For some reason, it is extremely easy to follow along with everything you're saying.
    You earned a new sub forsure.

  • @MandolinSashaank
    @MandolinSashaank Před 2 lety +1

    I would literally invest a fortune to get any of your courses. The way you explain stuff just blows my mind! I can never be thankful enough for all of this!

  • @sonatartica2590
    @sonatartica2590 Před 3 lety

    I am struggling to become an hybrid tester, being a functional QA for over 8 years but your videos are really helping me a lot to achieve my goal in order to grow further in my IT career! THANKS!!!

  • @chairjacker
    @chairjacker Před 26 dny

    Ive been trying to use chatgpt for a selenium project, but looking the descriptions on this series I'm delighted to go throughly through all these tutorials so i may actually get this project of mine done. Thanks so much for being consistent and thorough in your tutorials.

  • @alecouto
    @alecouto Před 3 lety

    Several times I got myself stucked in minor mistakes using Selenium, sometimes mine, some from the books, and here made it so easy to follow.
    Have my subscription and my Like, Sir.

  • @KrispyKruiser
    @KrispyKruiser Před 3 lety

    Your the best python tutor ive seen. Seriously great detail, the use cases are helpful as well, everything. top notch.

  • @felipeleon5647
    @felipeleon5647 Před 3 lety +15

    I consider that Tom is one of the best teachers in computer science that I´ve watched. Please continue by explaining different topics in python. Thanks

  • @TheAInfinity
    @TheAInfinity Před 4 lety +35

    Great tutorial for Selenium. It's important to note that Selenium is very slow, and for any large scale project, it would take minutes (sometimes hours) to finish running, so this web scraping approach should be the last option to be used for websites with heavy JavaScript. The practical approach would be to send a GET request to the URL of the website and adding the search query to the end of the URL and then parsing the response. You can see at 5:30, the URL has the query add "?s=test". This is the same approach but maybe 100 times faster than using Selenium.

    • @danfog7370
      @danfog7370 Před 3 lety

      What is the name of this practical approach, or are there any tutorials you can refer me to? I've realised this selenium tutorial is great but not practical for a site with large scale data

    • @alenjose3903
      @alenjose3903 Před 3 lety +1

      @@danfog7370 regular webscraping using requests

    • @playstationnextgenil491
      @playstationnextgenil491 Před 3 lety

      That can be very hard at times though. As most websites tend to obfuscate these kind of things.

    • @YourMom-du5ud
      @YourMom-du5ud Před 2 lety

      Yep. It's easy to use with websites that deliberately obfuscate how they work to prevent automatic interaction, though. For example, I wrote a simple API to upload and download photos from and to Amazon Photos, which really doesn't work by using normal requests.

    • @drygordspellweaver8761
      @drygordspellweaver8761 Před rokem

      @user-bg2pl1we7x you mean that you wrote a simple *script*. Not an API. An API is literally what requests work through.

  • @santiagogaborovmilich7887

    This is exactly what I was looking to understand web scraping. Amaizing tutorial! Thanks so much for sharing it.

  • @nczioox1116
    @nczioox1116 Před 4 lety +1

    Probably one of the best Python tutorial channels on CZcams

  • @user-dy5ho4sj2w
    @user-dy5ho4sj2w Před 4 lety

    I went through this video twice because the material has been so useful. Thank you again!

  • @artyom9499
    @artyom9499 Před 2 lety

    Thank you Tim for complicating things in the end of the video, making it even more challenging to understand.

  • @KhalilYasser
    @KhalilYasser Před 4 lety +5

    Awesome Tim. As for the headers I used this line
    header = article.find_elements_by_tag_name("a")[0]
    then
    print(header.get_attribute('innerText'))

  • @caioglech
    @caioglech Před 4 lety +4

    Congratulations on the video. Keep bringing us more of those on Selenium. Especially regarding most common errors such as Stale Element Reference Exception and No Such Element. It could be very helpful.

  • @heathengaming8461
    @heathengaming8461 Před 4 lety +49

    Looking forward for more selenium tutorials 👏

    • @kennethgan1333
      @kennethgan1333 Před 4 lety

      www.udemy.com/course/learn-selenium-automation-in-easy-python-language/learn/lecture/16983696?start=1#overview

  • @arjunprasadsarkhel7814
    @arjunprasadsarkhel7814 Před 4 lety +18

    Thank you Tim for this, looking forward fof more

  • @qusek6446
    @qusek6446 Před 2 lety

    NEVER STOP MAKING THIS CONTENT IT IS EXTREMELY VALUABLE THANK YOU SO MUCH FOR EXISTING

  • @andrewromano6351
    @andrewromano6351 Před 3 lety

    Dear Tim, OMG WOW! This is a life changer!!!
    With this, anything is possible.
    THANK YOU!

  • @sephirothu1290
    @sephirothu1290 Před 2 lety

    Hey man
    I just wanted to say: you have the gift of simplifying complex things. God Bless You.

  • @Helpmecry
    @Helpmecry Před 3 lety +87

    If i have a moral to tell anyone about learning tutorials: "Don't just pause the video and go faster than Tim i literally spent half an hour trying to figure out an error that Tim was just about to explain 😂 " : 8:40

  • @danaraujo7870
    @danaraujo7870 Před 3 lety

    Tim is the GOAT. Easily on par with the UMich courses on coursera (but where they teach you the language, he gives these awesome tutorials to show what you can really do with it).

  • @heidisdiy6888
    @heidisdiy6888 Před 4 lety +1

    Thank you, thank you, thank you for this tutorial! You explain things very clearly! I hope you keep on making these videos!

  • @fmostream
    @fmostream Před 4 lety +1

    Love your tutorials, this one really helped me out starting up with selenium

  • @fabu324
    @fabu324 Před 4 lety

    Great new tutorial! You're just awesome man and I've earned so many coding skills from you!!!

  • @atbox7535
    @atbox7535 Před 2 lety +1

    Hello Tech with Tim, your Selenium python tutorial is amazing it gave me an way better understanding then documentation. Thanks for the tuturial.

  • @danielmonteleone5850
    @danielmonteleone5850 Před 3 lety

    appreciate you man I have so many ideas for how I'm going to use what I learned, so much practical info.

  • @enoch5267
    @enoch5267 Před 3 lety

    Best Programming CZcamsr Ever!!!!
    Thanks for your Tutorial Tim.. Very Understandable Thanks!!!

  • @user-vw3pr5gq9g
    @user-vw3pr5gq9g Před 3 lety

    frankly speaking ,Tim is just an amazing teacher

  • @rikittu
    @rikittu Před 4 lety

    Thank you for this. Im looking forward to all the parts of this series

  • @apratimghosh109
    @apratimghosh109 Před 4 lety +1

    Amazing tutorial, everything worked perfectly. Thank you!

  • @BM-vz2nb
    @BM-vz2nb Před 3 lety

    you are doing a great job Tim! Thanks a lot for your efforts!

  • @vonesha
    @vonesha Před 4 lety

    Please keep up the good work. Following this series!

  • @annaburshtyko5714
    @annaburshtyko5714 Před 3 lety +1

    Very useful tutorial, thanks a lot!

  • @DanNorris81
    @DanNorris81 Před 4 lety

    THANK YOU for these videos!
    Highly appreciated videos!

  • @TopBagon
    @TopBagon Před 4 lety +1

    Amazing job. Learning from you is surprisingly easy

  • @2c0bb61
    @2c0bb61 Před 4 lety +1

    Good content, thanks for putting your time and effort into this. Definitely worth a like

  • @sivaaj8504
    @sivaaj8504 Před 4 lety

    It's been a while I came across a good tutorial. Thanks !!

  • @oseiryth
    @oseiryth Před 2 lety

    i rarely subscribe but your contents are very concise and technical, that i had to subscribe; more power to your channel.

  • @pierrevvr
    @pierrevvr Před 3 lety +1

    this playlist is dope! thanks bro, cheers from france

  • @sohansoharab1670
    @sohansoharab1670 Před 4 lety +198

    The difference betwn "find_element" and "find_elements" is single item vs list

    • @Jamesandrews1997
      @Jamesandrews1997 Před 4 lety +17

      Bro, I had no idea why my code wasn't working. Thank you!

    • @debajyotidas4549
      @debajyotidas4549 Před 3 lety +1

      Thnx for mentioning, couldn't find the send_keys().

    • @Lahmeinthehouse
      @Lahmeinthehouse Před 3 lety +1

      THANK you!!! Great clarification :)

    • @stark2461
      @stark2461 Před 3 lety +5

      thank you man, i was getting error like 'list' object has no attribute 'send_keys'

    • @j43fura71
      @j43fura71 Před 3 lety

      thank you brother

  • @DrSebastianFranciscoAntonio

    Incredibly helpful, thank you tim

  • @ramizquliyev394
    @ramizquliyev394 Před 3 lety

    You are amazing!!! Normally I don't like to write comment but I just want to support you. Thanks a lot

  • @gloryness
    @gloryness Před 4 lety +9

    Btw, there is a "main" ID on the first page too, and for me it got that instead of the second page.
    It's an easy fix, just put time.sleep(5) a few lines before the try statement.

  • @mv848
    @mv848 Před rokem

    Amazing, thank you so , so much! It works like a charm every time.

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

    Wow, this video provided the help I´ḿ looking for to resolve some work issues. Thanks!

  • @morty6224
    @morty6224 Před 4 lety +1

    Thank you for teaching this on free.
    Love you😍😍😍😍

  • @duke4279
    @duke4279 Před 4 lety

    Awesome explanation and great contents, liked and subscribed!!

  • @namesarnav
    @namesarnav Před 3 lety

    All I wanna say is...THANK YOU SO MUCH FOR THESE VIDS

  • @samchan45
    @samchan45 Před 2 lety

    starting a new job, and you are a godsend!

  • @julian3833
    @julian3833 Před 4 lety

    You rock Tim, great work!

  • @climax_set_bird464
    @climax_set_bird464 Před 3 lety +15

    Just remember that you have to type find_elements_by_class_name etc. because there could be more than one of the same class name. Typing find_element_by_class_name etc. will throw an error.

  • @fatimansarizadeh
    @fatimansarizadeh Před 4 lety +1

    Many tnx Tim. U r doing perfect work. Can you please consider talking about preprocessing datasets like NELL.

  • @aryanyekrangi7093
    @aryanyekrangi7093 Před 4 lety

    I love your videos! so detailed!

  • @kheshavlg
    @kheshavlg Před 4 lety

    AWESOME video waiting for the next one !!!!!!!!!!!!!!!!!!!!

  • @yaagikmaurya4843
    @yaagikmaurya4843 Před 3 lety

    Thanks for such a great tutorial it's simple though very useful

  • @jean.lucasls
    @jean.lucasls Před 15 dny

    This video is better than so many paid courses!

  • @vaibhavjain1914
    @vaibhavjain1914 Před 3 lety

    man I love your video gonna make a bot to attend my online classes with this, thanks dude 😉😉

  • @phonylattice2743
    @phonylattice2743 Před 4 lety

    Thank you so much for this tutorial!

  • @mandyssugarshack6414
    @mandyssugarshack6414 Před 2 lety

    You are an amazing teacher!

  • @stephenduff1917
    @stephenduff1917 Před rokem +5

    Please update the video for the new code

  • @mikerope5785
    @mikerope5785 Před 2 lety

    i think the titles weren't printing because they were nested inside an anchor tag. you would have to add a line to find by tag name "a" for each "entry-title" and it would have printed. You are a great teacher Tim.

  • @BobbyTomMathew
    @BobbyTomMathew Před rokem

    This tutorial is incredible.

  • @mariorossi1456
    @mariorossi1456 Před 4 lety +1

    Really helpful! Keep it up!

  • @saadaddine6422
    @saadaddine6422 Před 4 lety

    This is great. You're the best

  • @mpower3435
    @mpower3435 Před 3 lety

    Thanks for your efforts Tim

  • @CochDot
    @CochDot Před 3 lety +1

    Amazing tutorials for selenium .... Thanking you
    With regards,
    Indian Tubers

  • @RubyPiec
    @RubyPiec Před 4 lety

    Only subbed cause you came in my reccomendations, love programming and am named Tim

  • @Kaloris24
    @Kaloris24 Před 4 lety +1

    Great job Tim! Recent subscriber and happened to see the start of this series recently. Trying to watch 1 video of yours before work (2nd shift ugh). I love Python as well. I was wondering if you could do a Go tutorial series if you get time please? Especially since it's newer and that you are good at teaching. Thank you.

    • @TechWithTim
      @TechWithTim  Před 4 lety +1

      Ya id actually love to do go! Definitely on my list

  • @paulsamuel9649
    @paulsamuel9649 Před 4 lety +1

    Really helpful. THANKS👍

  • @paweszczepanski6738
    @paweszczepanski6738 Před 3 lety

    Tim, You are the best.

  • @zeroxx131
    @zeroxx131 Před 3 lety

    Thank you so much! Subscribed!

  • @sohansoharab1670
    @sohansoharab1670 Před 4 lety +1

    Nice.. Please by the end of the series, discuss about the difficulties and dependencies on collecting data from dynamic websites and SPA.. Please that would be really beneficial.. And I appreciate your effort.. Thank you so much!
    Beacuse for example: sometimes some websites shows valid src in img tag but after scrapping with selenium they become dummy like DATA:jsoockepskfuoe......== something
    I didn’t find the issue yet

  • @luisbarbosa5597
    @luisbarbosa5597 Před 3 lety

    awesome tutorial. tyvm bro!

  • @atulram8206
    @atulram8206 Před 3 lety

    @Tech With Tim, The glitch you are talking about (7:00) is the opacity for the entry-title class is 0%
    .entry-title {
    color: orange;
    opacity: 0%;
    }

  • @paulohsgoes1959
    @paulohsgoes1959 Před 3 lety

    Excellent job. Congrats

  • @hempen1
    @hempen1 Před 3 lety

    Tim, Thank you for this course. However, when I try to pull the content from the search, my driver and content continue to pull text from your home page opposed to the updated search page content. It is as if the driver is not updated to the new page. Any help would be appreciated. I am using Firefox driver, if that makes a difference.

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 Před 3 lety

    3:27 Notice we have both “find_elements_by_class_name” and “find_element_by_class_name”. I suspect what you said earlier about only finding the first instance of an element with a specified class applies to the latter call, not to the former; the former one would let you iterate through them all.

  • @arshadedris
    @arshadedris Před rokem

    Thank you so much Tim I really Appreciate your time, help and effort. I have seen all of your tutorials in every section of SDET that was amazing and understandable.
    I just wanna know about the name of application that you are working in this video, wanna start practicing by watching your video and try with myself.
    Thank you !!!

  • @user-uk8we4bx9o
    @user-uk8we4bx9o Před 4 lety

    Thank you for your series

  • @pro1427
    @pro1427 Před 2 lety

    said it before, gonna say it again: BOSS!

  • @jacobdev
    @jacobdev Před 2 lety +1

    Hi Tim, what are you using for autocomplete in sublime text for python? That is showing you diffrent functions that you can use.

  • @dnetne5508
    @dnetne5508 Před 4 lety +1

    Excellent!

  • @bluedragonn1
    @bluedragonn1 Před 4 lety +1

    Men I wish all of my teachers explain my classes as you

  • @jiaofeng6639
    @jiaofeng6639 Před rokem

    Super super awesome and helpful 😊😊😊

  • @estherm6464
    @estherm6464 Před 3 lety

    I don't know how else to say this, I love you.

  • @rafj9883
    @rafj9883 Před 4 lety

    Thanks Tim!

  • @chiragchhillar2958
    @chiragchhillar2958 Před 4 lety

    please bro i am waiting for you to arrange the playlist. U teaches very well bro. I am from india and i loved the way u explain

  • @cuteypatootie
    @cuteypatootie Před 2 lety

    Hi Tim! Thanks for the awesome videos I’m a new subscriber and love the content. I have a question: is it more efficient to grab a section like this and iterate through it, or would it just be better to select all of those articles headers text using 1 line xpath? Perhaps you showed it this way in case we want to extract more data than just the headers?
    Also, I find myself using web driver wait on almost all element location to ensure I am waiting for DOM. Is this correct? Seems like code redundancy. (Figured out how to solve this part in part 6!)
    Thank you so much!

  • @freezaki7302
    @freezaki7302 Před 4 lety

    Wow, great tutorial

  • @808rjsv
    @808rjsv Před 2 lety

    Thanks Man!

  • @colednicholas88
    @colednicholas88 Před 4 lety

    You are the absolute man . . .

  • @techify5895
    @techify5895 Před 3 lety +3

    For some reason my chrome browser quits when it is opened through Selenium even if there is no quit command. Can someone help me fix this?

  • @seatownrocks
    @seatownrocks Před rokem +1

    Hey Tim, @3:21 you show selenium completions in Sublime but I am not getting any of those. How did you set that up? Great videos, thanks.

  • @akshatsingh7286
    @akshatsingh7286 Před 4 lety

    Keep doing this!!!

  • @TheGlorinha11
    @TheGlorinha11 Před 3 lety

    THANK YOU!

  • @benmuyal1
    @benmuyal1 Před 2 lety

    Great content!