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??
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 .
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
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.
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 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)
@@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();
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.
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?
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.....
📌 Selenium Interview Questions Playlist Link: bit.ly/3matUB3
✴ Checkout my other playlists: bit.ly/3gLIAVL
☕ Buy me a coffee: bit.ly/33ljBWc
want to talk with you. mail me if possible naveenrathore.214@gmail.com
Reach out to me on hyadagirireddytutorials@gmail.com
Your Explanation is awesome thank you for such useful videos
super explanation sir
Thank you buddy
Super Brother
Nice Explanation
Thank you bro 🙂
Thank you so much sir for made this video.
Happy learning buddy 😊
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??
You can use the index for achieving this.
Try this: (//a[text() ='download'])[2]
@@HYRTutorials yes sir.. This is what I did.. Working fine.. Love u so much brother ✨
@@ilavarasansriraman4140 taking 2nd index value by using xpath : (//xpath)[2]
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 .
It's almost similar to this one.
We have to use httpclient class to verify the images
H Y R Tutorials do you have video of finding all broken images? Please , really want to see it .
@@ioriiori I don't have but will make the video on that.
H Y R Tutorials thank you so much , you are so kind 😊
@@HYRTutorials Thanks a lot , I'm also waiting for your video about find all broken images ,thank you ,my brother ,you are so nice .
Very good explanation sir👌
Thankyou
good Explanation
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
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
Hi Could you make a videos on Integration API automation test? using Post Man ? - Thanks!
I have no idea about that
sir after doing this program for me not getting any error just showing total number of present on the webpage is: 0
Can u send me the script on hyadagirireddytutorials@gmail.com
How can we do this protractor? Is there any package available in npm?
No idea about protractor dude
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.
Send me the code on hyadagirireddytutorials@gmail.com
When I ran your code I get StaleElementReferenceException. do you know why?
May be the page is refreshed before clicking on the element
@@HYRTutorials How to fix it??
Stale element reference: element is not attached to the page document
@@mupparajuveeranji5113 Only solution is to handle that link in try catch block
Great tutorial 👍
Bro while doing Broken links iam getting Stale Element Exception Pls Tell How to Handel it
in Broken links
Can you send me your code on hyadagirireddytutorials@gmail.com.
I need to understand in which scenario you are getting that exception
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.
I think you are using findelement method instead of findelements method
@@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)
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);
}
}
}
@@sumitanand1373 remove the proxy creation.
It is required only when u r working on some private network like vpn in your office
@@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);
}
}
I'm getting WebdriverManager error after public static void main
Can u paste the full error here or can you send me the screenshot of that error on hyadagirireddytutorials@gmail.com
Add webDriver Dependencyin the POM file
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.
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.
@@HYRTutorials Thanks a lot ,I will keep learning then .
@@HYRTutorials when I run the coding it's shows like not found 404
@@subaidhasy1771 so that means the page is not available
@@HYRTutorials why
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?
I don't think that error has something to do with selenium
Thank you 😊
Happy learning buddy 😊
Thank you so much bro
Happy learning buddy
Briefly explained 👍👍
Thankyou, keep watching.
How to find whether url is secured or not ??
You can verify whether it is http or https.
Hi could you please share code in description?
The link is already in the description buddy
Same code can u please make on python as well
The concept is going to be same buddy.
You can try with python and if you get stuck let me know
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.....
Do u know python language buddy?
If you know then implementing logics using basic programming is easy.
Ok
So fast teaching
Sorry for that buddy.