How to Find Broken Links using Selenium WebDriver? | selenium interview questions |

Поділитися
Вставка
  • Опубліковано 15 жов 2024

КОМЕНТАРІ • 91

  • @HYRTutorials
    @HYRTutorials  4 роки тому +1

    📌 Selenium Interview Questions Playlist Link: bit.ly/3matUB3
    ✴ Checkout my other playlists: bit.ly/3gLIAVL
    ☕ Buy me a coffee: bit.ly/33ljBWc

    • @abslutedesi3021
      @abslutedesi3021 4 роки тому

      want to talk with you. mail me if possible naveenrathore.214@gmail.com

    • @HYRTutorials
      @HYRTutorials  4 роки тому

      Reach out to me on hyadagirireddytutorials@gmail.com

  • @gayathrivegesna7464
    @gayathrivegesna7464 Рік тому

    Your Explanation is awesome thank you for such useful videos

  • @rihanya_jethin4593
    @rihanya_jethin4593 2 роки тому +3

    super explanation sir

  • @harishgajjela4191
    @harishgajjela4191 4 роки тому +2

    Super Brother
    Nice Explanation

  • @C.Sakthivignesh
    @C.Sakthivignesh Рік тому +1

    Thank you so much sir for made this video.

  • @ilavarasansriraman4140
    @ilavarasansriraman4140 3 роки тому +2

    Interview question that I faced today :
    page contains 2 download links
    How to click the second download link using linktext?
    //a[text() ='download'] this xpath - 2 matching found..
    I am not able to locate the second download link using proper xpath.
    Could u pls give me a solution for this??

    • @HYRTutorials
      @HYRTutorials  3 роки тому +4

      You can use the index for achieving this.
      Try this: (//a[text() ='download'])[2]

    • @ilavarasansriraman4140
      @ilavarasansriraman4140 3 роки тому +2

      @@HYRTutorials yes sir.. This is what I did.. Working fine.. Love u so much brother ✨

    • @KaranSharma-lm6eh
      @KaranSharma-lm6eh 2 роки тому +1

      @@ilavarasansriraman4140 taking 2nd index value by using xpath : (//xpath)[2]

  • @ilyasyar
    @ilyasyar 4 роки тому +1

    Nice video, thanks a lot ,and is there anyway to find images ? all 3 types of images if they are show or they are damaged on the website , Thanks ,please let me know .

    • @HYRTutorials
      @HYRTutorials  4 роки тому +1

      It's almost similar to this one.
      We have to use httpclient class to verify the images

    • @ioriiori
      @ioriiori 4 роки тому +1

      H Y R Tutorials do you have video of finding all broken images? Please , really want to see it .

    • @HYRTutorials
      @HYRTutorials  4 роки тому +1

      @@ioriiori I don't have but will make the video on that.

    • @ioriiori
      @ioriiori 4 роки тому +1

      H Y R Tutorials thank you so much , you are so kind 😊

    • @ilyasyar
      @ilyasyar 4 роки тому +1

      @@HYRTutorials Thanks a lot , I'm also waiting for your video about find all broken images ,thank you ,my brother ,you are so nice .

  • @shubhamkori2805
    @shubhamkori2805 4 роки тому +1

    Very good explanation sir👌

  • @ChayaE-yw8tm
    @ChayaE-yw8tm 4 місяці тому

    good Explanation

  • @shreyanshsingh2782
    @shreyanshsingh2782 2 роки тому +1

    sir why proxy issues will come in company not at home , what is a proxy why we need to set , if you can make a video it will be hepful

    • @HYRTutorials
      @HYRTutorials  2 роки тому +1

      In companies they will use proxy for not allowing any unknown internet traffic.
      That's why u can't open all the websites and u can't download everything.
      To download anything behind this proxy, you need to talk to the IT team in your company.
      They can explain even better

  • @ulissesdasilva1314
    @ulissesdasilva1314 4 роки тому +1

    Hi Could you make a videos on Integration API automation test? using Post Man ? - Thanks!

  • @rihanya_jethin4593
    @rihanya_jethin4593 2 роки тому +1

    sir after doing this program for me not getting any error just showing total number of present on the webpage is: 0

    • @HYRTutorials
      @HYRTutorials  2 роки тому

      Can u send me the script on hyadagirireddytutorials@gmail.com

  • @pradeepjana1427
    @pradeepjana1427 4 роки тому +1

    How can we do this protractor? Is there any package available in npm?

  • @aswathys8884
    @aswathys8884 Рік тому

    While executing this code, it shows the links with status 200 & broken links too, but after printing a few links, it is showing an error message: "stale element reference: element is not attached to the page document". Rest links status as well as the driver.quit() is not getting executed.

    • @HYRTutorials
      @HYRTutorials  Рік тому

      Send me the code on hyadagirireddytutorials@gmail.com

  • @bulatshukanov8764
    @bulatshukanov8764 3 роки тому +1

    When I ran your code I get StaleElementReferenceException. do you know why?

    • @HYRTutorials
      @HYRTutorials  3 роки тому

      May be the page is refreshed before clicking on the element

    • @mupparajuveeranji5113
      @mupparajuveeranji5113 3 роки тому

      @@HYRTutorials How to fix it??
      Stale element reference: element is not attached to the page document

    • @Bell4Fun
      @Bell4Fun 2 роки тому

      @@mupparajuveeranji5113 Only solution is to handle that link in try catch block

  • @sajtly-web-dizajn
    @sajtly-web-dizajn 8 місяців тому

    Great tutorial 👍

  • @shahulhameed-io8lj
    @shahulhameed-io8lj 2 роки тому +1

    Bro while doing Broken links iam getting Stale Element Exception Pls Tell How to Handel it
    in Broken links

    • @HYRTutorials
      @HYRTutorials  2 роки тому

      Can you send me your code on hyadagirireddytutorials@gmail.com.
      I need to understand in which scenario you are getting that exception

  • @sumitanand1373
    @sumitanand1373 3 роки тому +1

    Exception in thread "main" java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to java.util.List
    at br1.Broken_link.main(Broken_link.java:25)
    I am getting this error.

    • @HYRTutorials
      @HYRTutorials  3 роки тому +1

      I think you are using findelement method instead of findelements method

    • @sumitanand1373
      @sumitanand1373 3 роки тому +1

      @@HYRTutorials I corrected it but now another error as below:
      Exception in thread "main" java.net.UnknownHostException: hostname
      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at sun.net.NetworkClient.doConnect(Unknown Source)
      at sun.net.www.http.HttpClient.openServer(Unknown Source)
      at sun.net.www.http.HttpClient$1.run(Unknown Source)
      at sun.net.www.http.HttpClient$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.net.www.http.HttpClient.privilegedOpenServer(Unknown Source)
      at sun.net.www.http.HttpClient.openServer(Unknown Source)
      at sun.net.www.protocol.https.HttpsClient.(Unknown Source)
      at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source)
      at br1.BR3.main(BR3.java:39)

    • @sumitanand1373
      @sumitanand1373 3 роки тому +1

      Below is the entire code:
      package br1;
      import java.io.IOException;
      import java.net.HttpURLConnection;
      import java.net.InetSocketAddress;
      import java.net.Proxy;
      import java.net.URL;
      import java.net.URLConnection;
      import java.util.HashSet;
      import java.util.List;
      import java.util.Set;
      import org.openqa.selenium.By;
      import org.openqa.selenium.WebElement;
      import org.openqa.selenium.chrome.ChromeDriver;
      public class BR3 {
      public static void main(String[] args) throws InterruptedException, IOException


      {
      System.setProperty("webdriver.chrome.driver", "../Selenium/chromedriver.exe");
      ChromeDriver driver= new ChromeDriver();

      driver.get("www.hyrtutorials.com/");
      Thread.sleep(5000);
      Set brokenlinkUrls = new HashSet();
      List links = driver.findElements(By.tagName("a"));
      System.out.println(links.size());
      for (WebElement link : links) {
      String linkURL = link.getAttribute("href");
      Proxy proxy = new Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress("hostname", 80));
      URL url = new URL(linkURL);
      URLConnection urlConnection = url.openConnection(proxy);
      HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
      httpURLConnection.setConnectTimeout(5000);
      httpURLConnection.connect();

      if(httpURLConnection.getResponseCode() != 200)
      {
      brokenlinkUrls.add(linkURL);
      }
      // System.out.println(linkURL + " - " + httpURLConnection.getResponseMessage());
      // else
      // System.err.println(linkURL + " - " + httpURLConnection.getResponseCode() + " - " + httpURLConnection.getResponseMessage());

      httpURLConnection.disconnect();
      }
      driver.quit();

      for (String brokenLinkUrl : brokenlinkUrls) {
      System.err.println(brokenLinkUrl);
      }
      }
      }

    • @HYRTutorials
      @HYRTutorials  3 роки тому

      @@sumitanand1373 remove the proxy creation.
      It is required only when u r working on some private network like vpn in your office

    • @sumitanand1373
      @sumitanand1373 3 роки тому +1

      @@HYRTutorials I have removed the proxy creation but still error exist.
      Exception in thread "main" java.net.MalformedURLException
      at java.net.URL.(Unknown Source)
      at java.net.URL.(Unknown Source)
      at java.net.URL.(Unknown Source)
      at br1.BR3.main(BR3.java:34)
      Caused by: java.lang.NullPointerException
      ... 4 more
      NOTE: on the click of the BR3.java.34 it redirect me to the URL url = new URL(linkURL); this line of code.
      Kindly help. I need to implement in project. Thanks for your help.
      Below is the code
      import java.net.HttpURLConnection;
      import java.net.URL;
      import java.net.URLConnection;
      import java.util.HashSet;
      import java.util.List;
      import java.util.Set;
      import org.openqa.selenium.By;
      import org.openqa.selenium.WebElement;
      import org.openqa.selenium.chrome.ChromeDriver;
      public class BR3 {
      public static void main(String[] args) throws Exception


      {
      System.setProperty("webdriver.chrome.driver", "../Selenium/chromedriver.exe");
      ChromeDriver driver= new ChromeDriver();

      driver.get("www.hyrtutorials.com/");
      Thread.sleep(5000);
      Set brokenlinkUrls = new HashSet();
      List links = driver.findElements(By.tagName("a"));
      System.out.println(links.size());
      for (WebElement link : links) {
      String linkURL = link.getAttribute("href");
      URL url = new URL(linkURL);
      URLConnection urlConnection = url.openConnection();
      HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
      httpURLConnection.setConnectTimeout(5000);
      httpURLConnection.connect();

      if(httpURLConnection.getResponseCode() != 200)
      {
      brokenlinkUrls.add(linkURL);
      }
      // System.out.println(linkURL + " - " + httpURLConnection.getResponseMessage());
      // else
      // System.err.println(linkURL + " - " + httpURLConnection.getResponseCode() + " - " + httpURLConnection.getResponseMessage());

      httpURLConnection.disconnect();
      }
      driver.quit();

      for (String brokenLinkUrl : brokenlinkUrls) {
      System.err.println(brokenLinkUrl);
      }
      }

  • @sbc4071
    @sbc4071 3 роки тому +2

    I'm getting WebdriverManager error after public static void main

    • @HYRTutorials
      @HYRTutorials  3 роки тому

      Can u paste the full error here or can you send me the screenshot of that error on hyadagirireddytutorials@gmail.com

    • @Bell4Fun
      @Bell4Fun 2 роки тому

      Add webDriver Dependencyin the POM file

  • @ilyasyar
    @ilyasyar 4 роки тому +1

    Hello ,I am here again ...how can I use this script to find all broken links from whole website ,not only from one page ? please.

    • @HYRTutorials
      @HYRTutorials  4 роки тому

      That is not possible Ilyas. because the page content is loaded only when you open that page.
      By default when we open the homepage, the entire website content will not be loaded hence we can't verify all the links.

    • @ilyasyar
      @ilyasyar 4 роки тому +1

      @@HYRTutorials Thanks a lot ,I will keep learning then .

    • @subaidhasy1771
      @subaidhasy1771 2 роки тому +1

      @@HYRTutorials when I run the coding it's shows like not found 404

    • @HYRTutorials
      @HYRTutorials  2 роки тому

      @@subaidhasy1771 so that means the page is not available

    • @subaidhasy1771
      @subaidhasy1771 2 роки тому +1

      @@HYRTutorials why

  • @SayaliBhilawade
    @SayaliBhilawade 2 роки тому +1

    While executing this code I am facing error like PKIX path building failed and also unable to find valid certification path to requested target
    Can you plz make solution video on this?

    • @HYRTutorials
      @HYRTutorials  2 роки тому

      I don't think that error has something to do with selenium

  • @nipunijayasinghe3575
    @nipunijayasinghe3575 Рік тому +1

    Thank you 😊

  • @yaswanthtirupathi6551
    @yaswanthtirupathi6551 2 роки тому +1

    Thank you so much bro

  • @AnkitSingh-be4wi
    @AnkitSingh-be4wi 4 роки тому

    Briefly explained 👍👍

  • @chirunomulavenkatesh
    @chirunomulavenkatesh 3 роки тому +1

    How to find whether url is secured or not ??

    • @HYRTutorials
      @HYRTutorials  3 роки тому

      You can verify whether it is http or https.

  • @rajeshrao5099
    @rajeshrao5099 2 роки тому +1

    Hi could you please share code in description?

    • @HYRTutorials
      @HYRTutorials  2 роки тому

      The link is already in the description buddy

  • @nagalakshmiv1997
    @nagalakshmiv1997 2 роки тому

    Same code can u please make on python as well

    • @HYRTutorials
      @HYRTutorials  2 роки тому +1

      The concept is going to be same buddy.
      You can try with python and if you get stuck let me know

    • @nagalakshmiv1997
      @nagalakshmiv1997 2 роки тому

      Thanks for your reply, I was able print all the url and attribute value, I got stuck in, if condition like how to implement all that response code and all.....

    • @HYRTutorials
      @HYRTutorials  2 роки тому

      Do u know python language buddy?
      If you know then implementing logics using basic programming is easy.

  • @Naru-pg1wi
    @Naru-pg1wi 7 місяців тому

    Ok

  • @sonalibhad3764
    @sonalibhad3764 2 роки тому

    So fast teaching