ImageTag exists in the TR?

前端 未结 2 1126
野性不改
野性不改 2021-01-22 19:20

EDIT:

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

    string name = String.         


        
2条回答
  •  礼貌的吻别
    2021-01-22 19:53

    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 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

提交回复
热议问题