I want to know how to get the HTML tag information and write to a C# project variable. Remember that I can not change the HTML because I do not have access.
In the example below, it is necessary to save the following fields in the variables: Client, Company, Portal (as marked in the image)
This is the HTML code:
<div style="font-size: 10pt; font-weight: bold">Portais
</div>
<hr>
<form name="Form1" method="post">
<input type="hidden" name="operacao" value="1">
<input type="hidden" name="d" value="">
<input type="hidden" name="equipe" value="">
<input type="text" name="conteudo" maxlength="200" size="20" onkeyup="escolhe_opcao_pesquisa(this);">
<select name="opcao_pesquisa">
<option value="A">Ambiente</option>
<option value="C" selected="">CNPJ</option>
<option value="E">Nome do Portal</option>
<option value="P">Número do Portal</option>
<option value="R">Rede</option>
<option value="L">Release</option>
<option value="S">Sufixo Login</option>
</select>
<input type="submit" value="Pesquisar >">
</form>
<script>if(''!='') { document.Form2.endereco_ip.value='';}</script>
<div style="font-size: 10pt; font-weight: bold">Listagem
</div>
<hr style="height: 1px">
<table width="100%" cellpadding="2" cellspacing="1" border="1" style="border-collapse: collapse">
<tbody>
<tr style="background-color: #E8E8E8">
<td width="1%">
</td>
<td width="5%">
<b>Rede
</b>
</td>
<td width="5%">
<b>Tipo
</b>
</td>
<td width="5%">
<b>Portal
</b>
</td>
<td width="20%">
<b>Nome do Portal
</b>
</td>
<td width="10%">
<b>Franqueador
</b>
</td>
<td width="10%">
<b>Ambiente
</b>
</td>
<td width="10%">
<b>Endereço BD
</b>
</td>
<td width="15%">
<b>Endereço Páginas
</b>
</td>
<td width="5%">
<b>Release
</b>
</td>
<td width="5%">
<strong>Administrador</strong>
</td>
</tr>
<tr>
<td bgcolor="green" title="xxx">
</td>
<td>Nome_emp
</td>
<td>Cliente
</td>
<td>
<a target="_blank" title="Ao clicar no link abrirá a tela de consulta do módulo comercial." href="#">1149</a>
<img src="./Portais - MicrovixERP(empresa)_files/s_01blue.gif" title=""Chave de Acesso" para confirmar identidade de analista : 2179">
</td>
<td>Nome_emp
<b> - Empresa: 19;
</b>
</td>
<td>9841 - Nome - empresa
</td>
<td>Microvix A (95%)
</td>
<td>LINK.COM.BR
</td>
<td>
<a href="http://#" target="_blank"><font color="blue">http://#
</font></a>
</td>
<td>2.0
</td>
<td class="style1">
Here is my current code:
// Declaration of the global variable portalweb
public string portalweb;
// Button with function
public void btnCcnpj_Click_1(object sender, EventArgs e)
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://...");
IWebElement secondRow = driver.FindElement(By.CssSelector("tr:nth-of-type(2)"));
IWebElement client = secondRow.FindElement(By.CssSelector("td:nth-of-type(3)"));
IWebElement portal = secondRow.FindElement(By.CssSelector("td:nth-of-type(4) a"));
IWebElement nomeDoPortal = secondRow.FindElement(By.CssSelector("td:nth-of-type(5)"));
portalweb = portal;
}
// TextBox where the HTML data should appear (in this example the number: 1149)
private void txbPortal_TextChanged(object sender, EventArgs e)
{
txbPortal.Text = portalweb;
}
But I am getting the following error:
Error CS0029 Can not implicitly convert type OpenQA.Selenium.IWebElement em string
element.GetAttribute("innerHTML");
IWebElement
to astring
. You should assign the text of the web element instead, likeportalweb = portal.Text