Locating a button element using Selenium on a website

Searching for a troublesome button on my website has become quite the challenge. Everything else seems to be found easily except for this one elusive element that's causing me frustration.

The HTML code is as follows:

<table class="d_FG" role="presentation">
<tbody>
<tr>
<tr id="z_t">
<td class="fct_w" colspan="2">
<div>
<input name="newAttachments_fsid" value="0" type="hidden">
<table id="z_u" class="dcs" role="presentation">
<tbody>
<tr style="border: none;">
<td colspan="3" style="padding-right:0">
<a id="z_v" class="vui-button d2l-button d2l_1_192_930" role="button" tabindex="0" aria-disabled="false">Add a File</a>
<a id="z_w" class="vui-button d2l-button d2l_1_193_372" role="button" tabindex="0" aria-disabled="false">Record Audio</a>
</td>
<td></td>
</tr>
</tbody>
</table>
</div>
 </td>
 </tr>
 </tbody>
 </table>

The specific element I'm struggling to find is:

<a id="z_v" class="vui-button d2l-button d2l_1_192_930" role="button" tabindex="0" aria-disabled="false">Add a File</a>

I've attempted different methods, such as:

    public void add_attachment(){
    driver.switchTo().defaultContent();
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    driver.findElement(By.id("z_v"))).click();

}

However, I simply can't seem to get it right. Every time I receive a message saying it's not visible or another element would be clicked instead.

I even tried using a JavaScript function to scroll down to the element, but unfortunately, that didn't work either. Any suggestions would be incredibly helpful at this point.

Answer №1

Have you considered trying alternative methods such as utilizing Actions or javascriptExecutor like the examples below?

WebElement btn = driver.findElement(By.id("z_v")));
Actions action = new Actions(driver);
action.click(btn).build.perform();

or

JavascriptExecutor js = (JavascriptExecutor)driver;
Js.executeScript("arguments[0].click()",btn);

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

Obtain the row ID from a database by selecting checkboxes

I am facing a challenge when trying to remove a row from my MS Access database using checkboxes on my JSP page. Each row in the displayed database has a checkbox, but I am struggling to retrieve the rowId and link each checkbox with its respective row. Any ...

JavaScript refuses to connect with HTML

Just starting out in the world of programming, I decided to dive into a Programming Foundations class on Lynda.com. However, after following along for fifteen minutes, I encountered an issue - I couldn't seem to connect my JavaScript file to my HTML f ...

Using the onclick event in JavaScript to create transition effects for swapping images

I am working on a website where I display 3 images. Instead of redirecting the users to a new page, I want to keep them on the same page. Question: How can I implement a functionality where clicking a <button> will display 3 new images in the view w ...

Concealing website links in the browser's address bar

Running my own website on a personal server with Ubuntu server, I noticed that my public IP address is displayed in the status bar when visitors browse my site or hover over links. Even after purchasing a domain name from godaddy, I couldn't find an o ...

Issue with the functionality of Jquery scrolling through thumbnail images animation

I have encountered an issue related to the previous question that I posted here. After successfully implementing the provided solution, it initially seemed to be working. However, when I clicked the next button and reached the 3rd click, the jQuery scrolli ...

Selenium encounters difficulty connecting to a docker container when executed with docker-compose run command

In my docker-compose.yml file, I have defined two services: a chrome-standalone container and a nodejs application. Here is the configuration: version: '3.7' networks: selenium: services: selenium: image: selenium/standalone-chrome-deb ...

What types of applications are compatible with Java Web Start?

I'm curious about the UI framework used by Java Web Start and how I can start developing with it. I use Netbeans but I find Java Web Start quite confusing. Can anyone explain it to me? ...

Error: Attempting to change a read-only property "value"

I am attempting to update the input value, but I keep receiving this error message: TypeError: "setting getter-only property "value" I have created a function in Angular to try and modify the value: modifyValue(searchCenter, centerId){ searchCenter.va ...

What steps should I follow to place my dropdown menu in the desired location?

I'm experiencing an issue with my dropdown menu. In the navbar, I have two dropdown menus - one for the user and the other for notifications. The user's dropdown works fine, but the notification dropdown appears to the left of my site when clicke ...

How to access a cash drawer in C/C++ or Java

Opening a cash drawer using C/C++ or Java is my current challenge. The cash drawer in question is a POS-X model with a USB connection. This is a new area for me to explore, and I discovered that the cash drawer is connected to the "COM3" port. Considerin ...

Optimizing Material UI Themes: Adjusting the spacing between labels and inputs for improved design

Currently, I am in the process of updating my MUI themes using the overrides functionality. This is how my input field looks like: https://i.sstatic.net/OFAGf.png I am looking to increase the space between the label and the input field. Below is the co ...

Show the HTML content fetched from the database using PHP

After pulling html source code from a database and storing it in a PHP variable, I noticed that the content consists of table rows structured like this: <tr><td>10:00 AM</td><td class="success">Available</td></tr> < ...

Is it possible to develop a script that can scrape data from various websites?

After creating nearly 30 unique scraping scripts for various websites, a friend mentioned the idea of consolidating all of them into one code file that could be used for dynamic scraping on a dashboard. However, I am skeptical about this approach since eac ...

Embedding videos in HTML

I am experiencing difficulties with embedding a video in my HTML file. I attempted to use a YouTube video, but when I open it in my browser, it displays an error message stating that the video is unavailable because YouTube has refused to connect. I also ...

Webpage not resizing when WebView orientation changes

While developing my android app, I encountered an issue with the WebView. When I am at the very top of the WebView and switch my phone to landscape mode, the webpage does not resize properly to fit the screen. It only takes up half of the screen. However, ...

Creating 3D audio effects in HTML5

Let's dive into the challenge... Currently, I'm working on building a virtual environment with WebGL (THREE.js) where various objects produce distinct sounds. My goal is to create a surround sound experience based on the position of these object ...

What is the best way to utilize jQuery to send JSON data and then parse it on a subsequent HTML page via the

My goal is to send JSON data through the URL to the next HTML page. While testing it on an emulator for a mobile app, I encountered an issue where the URL crashed instead of redirecting to the next page. Can someone help me understand why this might be hap ...

Display an image in a new window

Hey, I want to display an image in a separate window when it is clicked. Here is my HTML code snippet: <div data-role="content" class="jqm-content"> <h2>Photo popup example</h2> <div data-demo-html="true"> <a href="#popup ...

Disregard any mistakes and proceed to locate the following element

While reading a text from a page, I sometimes encounter missing elements during my search. In such cases, I would like to skip the non-existing element and move on to the next page. Is it possible to do so? This is the code snippet I am using: while True ...

A beginner's guide to implementing dot navigation within the Jackson JsonNode

Take a look at this code snippet: val parsedData = ObjectMapper().readTree(vcap) parsedData.get("spaces")?.firstOrNull()?.get("block1")?.asText() I'm interested in improving the readability of this code by using dot notation for navigation. Here&ap ...