I want to get all links with its response code in a website other than home page. I have tried using findElements method with anchor tag but this gives me links on home page only. Now suppose i have some menus also in that home page and i want to get links associated with that pages also. Is it possible??
How can we find all links in a website other than home page using java selenium
220 Views Asked by Vihangi Desai At
2
There are 2 best solutions below
0
arpita biswas
On
To get all active links present in webpage please try below code. If possible please share your test URL and code, then I can replicate it from my side.
List<WebElement> linksList = driver.findElements(By.tagName("img"));
linksList.addAll(driver.findElements(By.tagName("a")));
System.out.println("The full size of Links and Images are: "+linksList.size());
List<WebElement> activeLinks = new ArrayList<WebElement>();
for(int i=0; i<linksList.size(); i++) {
Thread.sleep(200);
System.out.println(linksList.get(i).getAttribute("href"));
if(linksList.get(i).getAttribute("href") != null) {
activeLinks.add(linksList.get(i));
}
}
Related Questions in JAVA
- Add image to JCheckBoxMenuItem
- How to access invisible Unordered List element with Selenium WebDriver using Java
- Inheritance in Java, apparent type vs actual type
- Java catch the ball Game
- Access objects variable & method by name
- GridBagLayout is displaying JTextField and JTextArea as short, vertical lines
- Perform a task each interval
- Compound classes stored in an array are not accessible in selenium java
- How to avoid concurrent access to a resource?
- Why does processing goes slower on implementing try catch block in java?
- Redirect inside java interceptor
- Push toolbar content below statusbar
- Animation in Java on top of JPanel
- JPA - How to query with a LIKE operator in combination with an AttributeConverter
- Java Assign a Value to an array cell
Related Questions in SELENIUM
- How to access invisible Unordered List element with Selenium WebDriver using Java
- Compound classes stored in an array are not accessible in selenium java
- Fail Upload file in Selenium webdriver using Robot class
- Selenium crashes Firefox, how to reset the used profile / where is the default profile?
- Selenium Driver Service not found exception
- Unable to read excel if cell/column has drop down list enabled for Selenium webdriver TestNG
- Selenium C#: Store element's position on graph as a variable
- Selenium webdriver for handling dynamic ckeditors
- What can cause `UnreachableBrowserException: Could not start a new session`?
- Click on the 'compose' button in gmail inbox page
- python - selenium change frame not working
- Selecting Options from a Drop Down Menu in C# using Selenium
- Validation without skipping the test cases if one fails
- How can i increase session timeout (which is 30 minutes by default)
- Load additional CONFIG file with values
Related Questions in TESTING
- How does Robot's Telnet library work?
- Behat doesn't load extensions?
- Load additional CONFIG file with values
- rails controller test failing non-deterministicly wrt state leak (I think)
- Ordering tests using trial twisted
- Unexcepted failed Gavel/Dredd test
- How to use Jasmine and CucumberJS with Protractor
- Django login tests session problems
- How to mock specific RequireJs dependencies while unit testing
- Test case for WCF REST Service
- how to test this business logic
- Protractor - How to get first or last CHILD value
- Factory Not Registered in rspec but found in console
- Pick out certain lines from files
- Selenium stops running after click() function runs
Related Questions in AUTOMATION
- Installing Teamcity build agent as a user: failed to install the service. selected account does not have enough rights
- Automating Telnet Scripts from .bat with a teamspeak instance
- schedule and automate sqoop import/export tasks
- Dynamic @Test generation in TestNG
- detecting a file downloaded in selenium java
- Can I automate auto-app installation on my Android device?
- C# Program automation - Program hangs/doesn't work
- Saving Excel workbook as PDF gives me an OLE error 800A03EC
- Appium-How to send SMS for login verification purpose during automation test
- How to maximize browser window with helium using Java?
- Appium iOS automation using Java : get element using accessibility Id?
- Looking to run automated jobs in .NET application
- How to click the back navigation button of the browser using helium?
- Firefox automatically choose certificate, without ui dialog
- Test class not found in selected project
Related Questions in WEB-TESTING
- Does asp.net webform encrypt data for a simple form?
- WebTestCase, Silex and $_GET
- Can anyone tell me how to print all the friend list in facebook using selenium webdiver?
- Selenium Webdriver on PowerShell SendKey function send keys on current active window, not the Selenium invoked browser
- Visual Studio 2015 Load Testing - Where is Webtest.AddCommentToResult exposed?
- Scripting access to a website using different ips
- Visual Studio Performance Coded UI - Popup Window broken, Because Web Test Recorder is causing it to open in a full window
- Selenium click() working but submit() isn't
- Webbench fork error
- How to determine the maximum number of connections to the Web site using Apache Jmeter
- Add a SQL Datasource to a Web Test
- Python Selenium - How do you click on every row element for column of web table?
- Elements look offset, yet no offset is applied
- Since Selenium IDE is unmaintained, how to write Selenium tests quickly?
- How to to extract response by XPath Extractor in JMeter?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Using this you can collect links from a page.
For all links they are not file links, you can loop this as well. Another thing is to check the response code, see https://www.baeldung.com/java-http-request.