Having trouble finding the element for an image of a body part using xpath

When using

driver.findElement(By.xpath(".//*[@id='bodyPartContainer']/div[1]")).click();
to select a part of the human body image, I'm encountering the following exception in webdriver:

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//*[@id='bodyPartContainer']/div[1]"}

<head>

    <body style="height: 100%">
        <div class="container-fluid">
            <div class="row">
                <!-- Name-->
                <div class="row rowTop">
                    <!-- Email -->
                    <div class="row rowTop">
                        <!-- Date of Birth-->
                        <div class="row rowTop">
                            <!-- Human Body Selection -->
                            <form id="vForm" class="form-horizontal" role="form" data-toggle="validator" novalidate="true">
                                <!-- Type of Request -->
                                    </div>
                                </div>
                            </form>
                            </div>
                            <div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                <script type="text/javascript">
                                    // JavaScript functions here...
                                </script>
    </body>

</html>

I would appreciate any assistance with this issue. Thank you.

Answer №1

It seems like the issue may be due to the absence of the specific element tag in your xpath.

Instead of using

.//[@id='bodyPartContainer']/div[1]
, consider trying
.//div[@id='bodyPartContainer']/div[1]
.

You could also use

.//*[@id='bodyPartContainer']/div[1]
if you prefer to wildcard the element type.

Answer №2

You need to include the tag name (div) in your xpath expression.

The basic syntax is:

driver.findElement(By.xpath(".//(tagName or else *)[@(attributename)='(attributevalue)']"))

Please correct your statement to match the following:

driver.findElement(By.xpath(".//div[@id='bodyPartContainer']/div[1]")).click();

If you prefer not to specify a tag name, you can use * instead of the tag name.

driver.findElement(By.xpath(".//*[@id='bodyPartContainer']/div[1]")).click();

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

Creating an HTML file with a Windows-inspired icon and file name design using CSS

I searched everywhere on the internet but couldn't find a solution. If anyone knows of a similar link to my question, please share it with me. I am trying to achieve a design similar to Windows icons and file names in HTML using CSS. Please refer to ...

Utilize Jquery to hide radio buttons, while allowing users to click on an image to display a larger version

My current HTML structure is restricted to SAAS, so I only have control over jQuery implementation. https://i.stack.imgur.com/OHB9K.jpg I am attempting to achieve a similar layout as shown in the image below. The main issue lies in how to (1) conceal ...

Import the CSV file and store it in a designated directory using JQuery

My goal is to enable users to upload a CSV file from an HTML page and have it saved to a specified local directory upon upload. Two possible scenarios could unfold: if the uploaded file already exists, it should be overwritten; otherwise, a new file shoul ...

Encountering yet another frustrating issue with z-index not functioning properly in versions of IE above 7, despite extensive research yielding no solution

I have scoured numerous resources and read countless articles on how to resolve z-index issues in IE 7, 8, and 9. However, none of the suggested solutions seem to work for my particular situation. The issue at hand is that I have interactive content posit ...

Having trouble extracting the Top-Level Domain from a URL

I'm struggling to find a reliable way to extract the Top-Level Domain from a URL. The challenge I'm facing is that the URLs entered by users can vary greatly - they might enter www.google.com, m.google.com, m.google.uk, google.uk, or www.m.google ...

What's the name of the auto-triggered dropdown menu feature?

Visit Amazon's official website Description: Within the 'Shop by Department' section- A drop-down menu that remains visible without requiring you to hover over it. However, when the browser is in a non-full-screen mode, the menu disappears ...

What is the best way to save newly added elements on a webpage that were submitted by the

I am looking for a way to save the changes made by users on my webpage so that they can navigate to different pages and come back without losing any added elements. These changes should be retained even when the user goes back to edit the webpage, but I pr ...

Creating a distinct file name for every execution in Log4jORGenerating a unique file name

I have an issue in my project with log4j where I am unable to create a new file each time I run the script. My requirement is to generate a file name in the format Filename_<DDMMYYYY_HHMMSS> every time the script runs. Despite trying different codes ...

Having difficulty selecting the element provided by the factory method

Hey there! I'm encountering an issue while trying to click on an element whose location is defined using PageFactory. It's throwing a NullPointerException. Locator class: @FindBy(xpath = "//*[@content-desc = 'Navigate up']") public By ...

Issues with HTML5 video playback in Apple machines using the Firefox browser

On a website I'm developing, I've included an HTML5 video that works perfectly except for one specific issue - it won't play on Firefox in Apple devices. Surprisingly, it functions well on all other browsers and even on Firefox in Windows an ...

Using the Markdown attribute in this context prevents the translate pipe from translating the string

I have a paragraph within an Angular component that includes a markdown attribute. Occasionally, the markdown is causing the translation pipe to not translate the title.description string: <p class="someClass" markdown>{{tile.description | ...

The exact measurement of width is not specified in the custom element that extends HTMLCanvasElement

I have created a custom element that extends a canvas, but when I try to add it to the DOM, the width appears to be undefined. Here is my code snippet. class Renderer extends HTMLCanvasElement { constructor() { super(); } } customElements.def ...

Tips for restricting the line length in email XSLT

I am currently working on creating a report that needs to be sent via email. However, I have encountered an issue where the lines get cut off if they exceed about 2040 characters in length by email daemons. I have been using XSLT to construct the email rep ...

Is it possible to improve the cleanliness of my code with jQuery chaining?

As I continue to delve into jQuery and expand my knowledge each day, I find myself wondering about ways to write cleaner code. One concept that intrigues me is 'chaining', but I am unsure of how to implement it. Here is a snippet of functional j ...

Is there a way to keep a div element stationary during scrolling without using fixed positioning?

Is there a way to prevent a div from moving when scrolling up or down without using the position:fixed property? When an element is fixed, the scroll bar disappears making it impossible to reach the element by scrolling. div{ position:fixed; top:1 ...

When adjusting the orientation on a mobile device, remember to close any popup windows that may

Adapting a desktop website for mobile use in landscape mode only. If users switch to portrait orientation, a message will prompt them to rotate the device. This feature is functioning as intended. The real challenge arises when displaying Javascript alert ...

Troubleshooting a Vue.js formatting problem in Visual Studio 2019

Encountering an issue with VS2019 while attempting to format this code section. <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="milestone.ascx.cs" Inherits="uc.dms.milestone" %> <section class="content-header"> <h1> ...

Is it possible to create repetitive events using loops in jQuery?

When it comes to specificity in coding... $("#ht_1").click(function () { alert("hello"); }); $("#ht_2").click(function () { alert("hello"); }); // here's what I attempted for (i = 1; i <= 2; i++) { $("#ht_" + i).click(function () { ...

Updating Multiple Divs with jQuery AJAX (Continuous Repeated Refreshing)

I've been trying for a while to solve this issue but haven't found a solution yet. My auto-refresh feature works, however, it refreshes all the divs inside each other. For example, I have a computer-aided dispatch application with sections for av ...

Tips for choosing multiple files with the Ctrl key in a list item element:

We have decided to create our own browsing functionality due to the limitations of the existing HTML browse feature. While using the HTML browse, we can only select multiple files by pressing the Ctrl key, and we want to replicate this feature in our custo ...