Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8675051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:51:15+00:00 2026-06-12T19:51:15+00:00

EDIT: public bool getImage() { IWebElement table = driver.FindElement(By.Id(DIV_ID_1)); string name = String.Format(//*[contains(text(), \'{0}\’)],

  • 0

EDIT:

public bool getImage()
{
    IWebElement table = driver.FindElement(By.Id("DIV_ID_1"));

    string name = String.Format("//*[contains(text(), \'{0}\')]", 'TEST1');
    IWebElement element = table.FindElement(By.XPath(name));
    IWebElement parent = element.FindElement(By.XPath(".."));

    try
    {
        IWebElement image = element.FindElement(By.XPath("//img"));
    }
    catch (NoSuchElementException e)
    {
        return false;
    }

    return true;
}

How would I find out if the TEST1 does have Image? in the below html source code, I have tr and within tr i have td and some tr may have image tag and some may not

So, I will be passing name for an example: TEST1 and in returns I will be expecting if the name has Image tag or not.

again, if I pass TEST2 and TEST3 it should return null since it does not have an image tag and where as TEST1 and TEST4 does have Image tag hence it should return me true.

I tried something like this but did not work:

string name = String.Format(".//td[contains(., \'{0}\')]/..//@src", "TEST1");
IWebElement element = driver.FindElement(By.XPath(name));

get this error: after trying the above code…

The xpath expression ‘.//td[contains(., ‘TEST1′)]/..//@src’
cannot be evaluated or does notresult in a WebElement

Below is the html source code

<div id="DIV_ID_1">
    <table id="TBLID1">
        <tr>
            <td>
                TEST1
            </td>
            <td>
                <img id="ctl00" src="../App_Themes/Default/images/phone.gif" />
            </td>
        </tr>
        <tr>
            <td>
                TEST2
            </td>
        </tr>
        <tr>
            <td>
                TEST3
            </td>
        </tr>
        <tr>
            <td>
                TEST4
            </td>
            <td>
                <img id="ctl02" src="../App_Themes/Default/images/phone.gif" />
            </td>
        </tr>
    </table>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:51:16+00:00Added an answer on June 12, 2026 at 7:51 pm

    So I would break this up into a few steps.

    First get your element:

    WebElement element = driver.findElement(By.xpath("//*[contains(text(), 'TEST1')]"));
    

    Then get the parent element:

    WebElement parent = element.findElement(By.xpath(".."));
    

    Then check the parent element for an <img> tag:

    Try
    {
        WebElement image = parent.findElement(By.xpath("//img"));
    }
    catch (NoSuchElementException e)
    {
        System.out.println("Did not find an image");
    }
    

    I’d wrap this in a function that I could then pass in the text to find the image and return the element if it exists.

    Something like:

    public WebElement getImage(String innerText)
    

    then just pass in TEST1 or TEST2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public ActionResult Edit(string param) { } http://localhost/Edit/5,someothervalue,etc How can i reach 'param' from a
I am getting a StackOverflow Error in this code: EDIT [XmlAttribute(ID)] public string ID
Edit: Added code (Exception on line 095, 5th time it's hit.) public DataTable ParseBarcodes(String[]
public void EditAndSave(String fileName) { Bitmap b = new Bitmap(fileName); /** * Edit bitmap
@RequestMapping(value = {/userDetails, /userDetails/edit/{id}}, method = RequestMethod.GET) public String userDetails(Map Model,****) { //what goes
I have this function: public static void Play(string FileName, bool Async = false) {
I've got the following classes: public class SupplierCategory : IEquatable<SupplierCategory> { public string Name
I have a class as follows class DataGridItem { public bool IsSpecial; public string
Here's my model: [Required] [Display(Name = "I'm a:")] public bool Sex { get; set;
I defined a class in Form1 as public class Conditions { public string name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.