Automating the process of clicking on an href within a div and span using Selenium WebDriver

On a wiki page with an extensive list of pages, I am attempting to click on a specific link. The code I am using is:

By SelectPageName = By.cssSelector("a[href='/wiki/display/TS/Test']");

However, when I run the code, I encounter the following error message: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"css selector","selector":"a[href='/wiki/display/TS/Test']"}

The structure of the HTML can be seen in the screenshot provided below.

I have searched through various questions on stackoverflow but none of the solutions seem to work for me. I have even attempted using PartialLink and Link methods without success. Any guidance would be greatly appreciated.View image here

Answer №1

To improve the loading time of an element, consider incorporating a waiting period. This will ensure that enough time is allotted for the element to fully load:

WebDriverWait wait = new WebDriverWait(driver, 30);           
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("a[href='/wiki/display/TS/Test']"));

If your intention is to click on the element, it is recommended to use the following method instead:

wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("a[href='/wiki/display/TS/Test']")));

The above function will verify that the element is both visible and enabled before proceeding.

If these solutions do not yield the desired result, please don't hesitate to reach out so we can further investigate the issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can you delete an element attribute using JavascriptExecutor in Selenium WebDriver?

I am currently facing an issue with setting up an auto bid on an auction site. The problem lies in the fact that the confirm button remains disabled until the user enters keypresses into the text field. Although I can populate the field using selenium.type ...

Having difficulty retrieving the city name from the website (goibibo.com)

New to using selenium, I am currently working on automating the website goibibo.com. My goal is to input "Chennai" into the "From" textbox using xpath, which prompts some suggestions. From those suggestions, I intend to select "Chennai". Utilizing Seleniu ...

Troubleshooting problem with input fields in Protractor due to sendKeys malfunction

My current task involves automating end-to-end tests using Protractor on an Angular application. However, I've encountered an issue with sending keys to input fields. The sendKeys function consistently misses a few characters each time it is used, so ...

The WebDriver in Java using Internet Explorer throws a "No element found" exception

Our team is looking to transition our tests to selenium 2, but we've encountered an issue that I'm not sure how to resolve. When using the following commands for webdriver: WebDriver driver = new InternetExplorerDriver(); driver.navigate().to(" ...

Exploring the capabilities of HTML5 canvas and integrating it with Selenium using Python

I have been working on testing a web server that is built using HTML5 with a canvas. While examining the source code for the login page, I noticed very minimal content. However, upon inspecting the element in Chrome, I discovered the following snippet: &l ...

What is causing the Wait.until() method to not function properly in Selenium WebDriver?

Currently I rely on Selenium WebDriver for my testing needs. In order to wait for an element to be present on the webpage, I have implemented the following code snippet: WebDriverWait wait = new WebDriverWait(driver, Long.parseLong(timeout)); wait ...

Executing selenium tests within a dockerized django environment

When it comes to running tests, my usual approach involves launching a separate container using the following command: docker-compose run --rm web /bin/bash The 'web' container contains django, and I typically run py.test from a shell periodica ...

Searching for an element using Python's Selenium and JavaScript

on this page I am trying to click on the "Choose file" button but I keep getting the error message: javascript error: argument is not defined var1 = sys.argv[1] path = os.path.abspath(var1) driver.get("https://www.virustotal.com/gui/home/upload& ...

Selenium error: Element not found - Element for login cannot be located

Attempting to leverage Selenium for downloading a file from . To access the file, logging in is required. However, encountering difficulty as an error is displayed when trying to fetch the email input field. Below is the code snippet: from selenium import ...

Guide to interacting with the Li element using JavaScript in Selenium

Is there a way to click on the item inside the li element using a Selenium script with JavaScript? I've tried different methods like By.cssSelector or by css, but I keep getting an ElementClickInterceptedError: element click intercepted:Other element ...

Unable to successfully transmit the driver input within the annotated test method

Here is the code snippet that I am currently using: @AfterMethod() public static void takeSnapShot(WebDriver webdriver, String fileWithPath) throws Exception { // Convert web driver object to TakeScreenshot TakesScreenshot scrShot = ((TakesScreens ...

What is the way to obtain a random element in Java code?

I need to select a random element from my Java code. Let's say I have 4 elements in my code and I want to start running the program from the second element, then switch to another element on each subsequent run. How can I achieve this? first ...

How can the driver effectively pause until a specific condition becomes true before resuming if it remains false?

I am currently in the process of automating a workflow that involves generating a report. Each time the report is generated, it takes a varying amount of time (for example, anywhere from 10 to 50 seconds). I am facing difficulty in finding an effective way ...

Encountering an issue while trying to execute a selenium application in the terminal: (Error message: ImportError - Unable to

Although I am a beginner in Python and Selenium, I have encountered an issue: When I execute my Python script using the IDLE (pressing F5), Selenium works perfectly (it opens Firefox, navigates to a website, and performs tasks). However, when I attempt to ...

Retrieve the inner text value from the third child element of an HTML using Selenium in Java

Here is the HTML code snippet: <h2 id="xyz" class="test"> <button class="restore 1" value="test2" title="hello"> Line1 </button> <button class="restore 2" value="test3" title="click"> Line2 </button> I need this text &l ...

Extracting data from a continually updating DataTable spanning multiple pages with a consistent URL

Currently, I have experience working with C and am in the process of learning Python as a hobby. My latest project involves scraping data from a dynamically generated table on https://www.justetf.com/it/find-etf.html?groupField=index&from=search&/i ...

Enhance your JavaScript code by replacing Promise syntax with Async syntax and utilizing map() instead of a traditional For

I have a code snippet here that is functioning properly. However, I am interested in converting the Promise code in the middle of the function to Async code and replacing the for loop with map(). Can someone guide me on how to achieve this transformation ...

A guide to pasting copied text from the clipboard using Selenium and Java on a Mac operating system

Having trouble pasting text into a textbox on MACOS? Trying to use the code snippet below, but Control + v and Command + v shortcuts are not working. It seems like this is a known issue, but unsure if it has been resolved yet. https://github.com/seleniumhq ...

Issue with updating Selenium ChromeDriverManager through a proxy network

I am trying to use selenium and Chrome with Python to access a website. Below is a snippet of my code: from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.service import Service # PROXY=&a ...

Having difficulty retrieving the values from the 'App.config' file within the Unit testing project using Nunit

In my 'nunit' project created in Visual Studio, I have a simple test but no default 'App.config' file. Therefore, I manually created an 'App.config' file and marked it 'Copy always' from the properties option. When ...