ImageTag existe no TR?
EDITAR:
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;
}
Como eu descobriria se oTEST1
temImage
? no código fonte html abaixo, eu tenho tr e dentro tr eu tenho td e alguns tr pode ter tag de imagem e alguns não podem
Então, vou passar o nome para um exemplo:TEST1
e em retornos estarei esperando se o nome tiver tag de imagem ou não.
novamente, se eu passarTEST2
eTEST3
deveriareturn
null
já que não tem uma tag de imagem e ondeTEST1
eTEST4
temImage tag
daqui deve retornar-me verdadeiro.
Eu tentei algo assim, mas não funcionou:
string name = String.Format(".//td[contains(., \'{0}\')]/..//@src", "TEST1");
IWebElement element = driver.FindElement(By.XPath(name));
obter este erro: depois de tentar o código acima ...
A expressão xpath '.// td [contém (.,' TEST1 ')] /..//@ src' não pode ser avaliada ou não resulta em um WebElement
Abaixo está o código fonte html
<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>