Selenium: How do I assert that a certain element is present in a certain cell of a certain table?

前端 未结 2 462
萌比男神i
萌比男神i 2021-01-18 07:37

I have a table on my page which is supposed to contain a certain element. I can identify the table by its name (it has a unique name), and I can also identify the element ea

相关标签:
2条回答
  • 2021-01-18 08:22

    Sounds like you want isElementPresent(...locator of element...). For example:

    $cell = "//table[@name='tableName']//tr[".$r."]/td[".$c."]";
    $foundLink = $this->isElementPresent("xpath=".$cell."/a[.='".linktext."']");
    $foundButton = $this->isElementPresent("xpath=".$cell."/button[@type='button']");
    $foundImage = $this->isElementPresent("xpath=".$cell."/img[ends-with(@src='pretty-pony.gif')]");
    

    isElementPresent() returns true if so, false if not.

    0 讨论(0)
  • 2021-01-18 08:35

    You could try Selenium's getXpathCount

    $this->("xpath=//table[@name='tableName']//tr[".$r."]//td[".$c."]//TAG");
    This will return the number of matches the xpath gets. in your case, zero would mean a fail.

    0 讨论(0)
提交回复
热议问题