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

我只是一个虾纸丫 提交于 2019-12-01 17:28:42

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!