我正在使用Selenium来自动化测试。我需要读取某些单元格的值。使用我的代码,我可以收集正确数量的单元格,这似乎是正确的单元格,但是在字段文本中,它没有显示任何值。我在其他表中使用了相同的代码,效果很好。
我正在过滤类名,我试图收集其他单元格,但它也没有显示文本。
单元格的代码如下:
<td class="RS_Celda_Contrato" align="right"> 3.131,69</td>
我的硒代码句子:
ReadOnlyCollection<IWebElement> celdasF = driver.FindElements(By.XPath("//*[@class=\"RS_Celda_Contrato\"]"));
在其他情况下,我使用了此技术。我已经像现在一样在集合中加载了元素,但是文本字段具有单元格的值。我要坚持要在集合中加载正确的行数,那么这不是框架可见性的问题,也不是表不是正确的表。
[编辑] html表的代码:
<frame name="hiddenFrame" src="/Operaciones/blanc.htm" scrolling="no" target="hidden" marginwidth="0" marginheight="0" noresize="">
<frame name="area" src="BasePage.aspx?a=1010" noresize="" scrolling="auto" target="area" marginwidth="0" marginheight="0">
<html>
<head id="Head1">[...]</head>
<body id="_body">
[...]
<table class="RS_Tabla" id="Tabla_Resumen_Saldos" xmlns="urn:Fibanc:Esquemas.xsd" cellspacing="0" cellpadding="4" border="0"><colgroup><col width="25px"><col width="545px"><col width="115px"><col width="115px"></colgroup><tbody><tr><td colspan="2" class="RS_Celda_Cabecera"><span style="text-transform:uppercase">Resumen de Posiciones</span>
<input id="_Checkbox Predeterminada" type="checkbox" checked="checked" onclick="javascript:__doPostBack('',this.checked)" style="vertical-align:middle"><span>Vista predeterminada</span><script type="text/javascript">
$(".hoverMenu").hover(function(){
$(this).css({"background": "url(/images/priv_tabs_fondo_on.gif) repeat-x", "color": "white", "cursor": "hand"});
}, function(){
$(this).css({"background-image": "none", "background-color": "#DDEDF9", "color": "black", "cursor": "default"});
}
);
function pulsaBoton1(){
$("#_MyWorld").click();
__doPostBack('', 'MyWorld2');
}
function pulsaBoton2(){
$("#_MyWorld2").click();
__doPostBack('', 'MyWorld');
}
</script><style type="text/css">
.flecha-up {
width: 0px;
height: 0px;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 7px solid #DDEDF9;
font-size: 0px;
line-height: 0px;
margin-left: 35%;
margin-top: 4px;
position: absolute;
</style><span style="font-weight:normal;" hidden="true">Vista predeterminada</span></td><td class="RS_Celda_Cabecera" align="center">Saldo (€)</td><td class="RS_Celda_Cabecera_Fin" align="center">Disponible (€)</td></tr><tr><td colspan="2" class="RS_Celda_Grupo">Cuentas a la Vista</td><td class="RS_Celda_Grupo" align="right">
3.657.933,91</td><td class="RS_Celda_Grupo_Fin" align="right">
3.651.397,25</td></tr><tr><td class="RS_Celda_Contrato"> </td><td class="RS_Celda_Contrato" style="border-left:none;"><a class="rs" href="javascript:doAction('2102', 'lci=10010506191378')">Cuenta Corriente ES30.0186.1001.91.0506191378</a></td><td class="RS_Celda_Contrato" align="right">
3.131,69</td><td class="RS_Celda_Contrato_Fin" align="right">
3.131,69</td></tr><tr><td class="RS_Celda_Contrato"> </td><td class="RS_Celda_Contrato" style="border-left:none;"><a class="rs" href="javascript:doAction('2102', 'lci=50010509275930')">Cuenta Corriente ES88.0186.5001.67.0509275930</a></td><td class="RS_Celda_Contrato" align="right">
1.942.482,31</td><td class="RS_Celda_Contrato_Fin" align="right">
1.942.482,31</td></tr><tr><td class="RS_Celda_Contrato"> </td><td class="RS_Celda_Contrato" style="border-left:none;"><a class="rs" href="javascript:doAction('2102', 'lci=10014500000120002')">Cuenta Divisa USD ES11.0186.1001.96.4500000120</a></td><td class="RS_Celda_Contrato" align="right">
1.712.319,91</td><td class="RS_Celda_Contrato_Fin" align="right">
1.705.783,25</td></tr><tr><td colspan="2" class="RS_Celda_Grupo">Fondos de Inversión</td><td class="RS_Celda_Grupo" align="right">
1.980.879,12</td><td class="RS_Celda_Grupo_Fin" align="right">
1.980.879,12</td></tr><tr><td class="RS_Celda_Contrato"> </td><td class="RS_Celda_Contrato" style="border-left:none;"><a class="rs" href="javascript:doAction('2401', 'lci=2250000013')">Fibanc Pensiones 22/50000013</a></td><td class="RS_Celda_Contrato" align="right">
2.182,47</td><td class="RS_Celda_Contrato_Fin" align="right">
2.182,47</td></tr><tr><td class="RS_Celda_Contrato"> </td><td class="RS_Celda_Contrato" style="border-left:none;"><a class="rs" href="javascript:doAction('2304', 'lci=102550619137')">Mediolanum Mercados Emergentes L 1025/50619137</a></td><td class="RS_Celda_Contrato" align="right">
695.164,31</td><td class="RS_Celda_Contrato_Fin" align="right">
695.164,31</td></tr><tr><td class="RS_Celda_Contrato"> </td><td class="RS_Celda_Contrato" style="border-left:none;"><a class="rs" href="javascript:doAction('2304', 'lci=105250619137')">Mediolanum Europa R.V. L 1052/50619137</a></td><td class="RS_Celda_Contrato" align="right">
1.283.532,34</td><td class="RS_Celda_Contrato_Fin" align="right">
1.283.532,34</td></tr><tr><td colspan="2" class="RS_Celda_Grupo">Planes de Pensiones</td><td class="RS_Celda_Grupo" align="right">
19.302,82</td><td class="RS_Celda_Grupo_Fin" align="right">
19.302,82</td></tr><tr><td class="RS_Celda_Contrato"> </td><td class="RS_Celda_Contrato" style="border-left:none;"><a class="rs" href="javascript:doAction('2405', 'lci=121760050048')">Europension Plan 1217/60050048</a></td><td class="RS_Celda_Contrato" align="right">
19.302,82</td><td class="RS_Celda_Contrato_Fin" align="right">
19.302,82</td></tr><tr><td colspan="2" class="RS_Celda_Grupo">Valores Depositados</td><td class="RS_Celda_Grupo" align="right">
0,00</td><td class="RS_Celda_Grupo_Fin" align="right">
0,00</td></tr><tr><td class="RS_Celda_Contrato"> </td><td class="RS_Celda_Contrato" style="border-left:none;"><a class="rs" href="javascript:doAction('2323', 'lci=118600661161')">Depósito de Valores 1186/00661161</a></td><td class="RS_Celda_Contrato" align="right">
0,00</td><td class="RS_Celda_Contrato_Fin" align="right">
0,00</td></tr><tr><td colspan="2" class="RS_Celda_Grupo">Otros Activos</td><td class="RS_Celda_Grupo" align="right">
154.149,91</td><td class="RS_Celda_Grupo_Fin" align="right">
154.149,91</td></tr><tr><td class="RS_Celda_Contrato"> </td><td class="RS_Celda_Contrato" style="border-left:none;"><a class="rs" href="javascript:doAction('2302', 'lci=121300338791')">All Funds 1213/00338791</a></td><td class="RS_Celda_Contrato" align="right">
154.149,91</td><td class="RS_Celda_Contrato_Fin" align="right">
154.149,91</td></tr><tr><td colspan="2" class="RS_Celda_Grupo">Challenge</td><td class="RS_Celda_Grupo" align="right">
217.120,93</td><td class="RS_Celda_Grupo_Fin" align="right">
217.120,93</td></tr><tr><td class="RS_Celda_Contrato"> </td><td class="RS_Celda_Contrato" style="border-left:none;"><a class="rs" href="javascript:doAction('2304', 'lci=121201116638')">Challenge 1212/01116638</a></td><td class="RS_Celda_Contrato" align="right">
217.120,93</td><td class="RS_Celda_Contrato_Fin" align="right">
217.120,93</td></tr><tr><td colspan="2" class="RS_Celda_Grupo">Best Brands</td><td class="RS_Celda_Grupo" align="right">
4.620.989,90</td><td class="RS_Celda_Grupo_Fin" align="right">
4.620.989,90</td></tr><tr><td class="RS_Celda_Contrato"> </td><td class="RS_Celda_Contrato" style="border-left:none;"><a class="rs" href="javascript:doAction('2304', 'lci=121200942557')">Best Brands 1212/00942557</a></td><td class="RS_Celda_Contrato" align="right">
2.878.381,79</td><td class="RS_Celda_Contrato_Fin" align="right">
2.878.381,79</td></tr><tr><td class="RS_Celda_Contrato"> </td><td class="RS_Celda_Contrato" style="border-left:none;"><a class="rs" href="javascript:doAction('2304', 'lci=121201227336')">Best Brands 1212/01227336</a></td><td class="RS_Celda_Contrato" align="right">
832.630,40</td><td class="RS_Celda_Contrato_Fin" align="right">
832.630,40</td></tr><tr><td class="RS_Celda_Contrato"> </td><td class="RS_Celda_Contrato" style="border-left:none;"><a class="rs" href="javascript:doAction('2304', 'lci=121201614619')">Best Brands 1212/01614619</a></td><td class="RS_Celda_Contrato" align="right">
909.977,71</td><td class="RS_Celda_Contrato_Fin" align="right">
909.977,71</td></tr><tr><td colspan="2" class="RS_Celda_Grupo">Index Linked Mediolanum International Life</td><td class="RS_Celda_Grupo" align="right">
499.980,00</td><td class="RS_Celda_Grupo_Fin" align="right">
475.862,97</td></tr><tr><td class="RS_Celda_Contrato"> </td><td class="RS_Celda_Contrato" style="border-left:none;"><a class="rs" href="javascript:doAction('2348', 'lci=121502025763')">DP Coupon Express Dual Barrier XXI 1215/02025763</a></td><td class="RS_Celda_Contrato" align="right">
499.980,00</td><td class="RS_Celda_Contrato_Fin" align="right">
475.862,97</td></tr><tr><td colspan="2" class="RS_Celda_Cabecera" align="right">
Total a su Favor</td><td class="RS_Celda_Cabecera" align="right">
11.150.356,59</td><td class="RS_Celda_Cabecera_Fin" align="right">
11.119.702,90</td></tr></tbody></table>
[...]
</iframe>
</body>
</html>
测试的完整代码:
[TestMethod]
public void TheFotografiaClienteTest()
{
TheLogInTest();
//Accesing the appropriate menu
driver.FindElement(By.Id("gestion_de_clientes_A")).Click();
//The operation is executed in a new window
string current = driver.CurrentWindowHandle;
PopupWindowFinder finder = new PopupWindowFinder(driver);
string newHandle = finder.Click(driver.FindElement(By.XPath("//*[@id=\"90002147\"]")));
driver.SwitchTo().Window(newHandle);
driver.SwitchTo().Frame(driver.FindElement(By.CssSelector("frame[name='area']")));
//Accesing a client
driver.FindElement(By.XPath("//*[@id=\"Template_FormControl_ccSelectorTitular_txtCliente\"]")).Click();
driver.FindElement(By.Id("Template_FormControl_ccSelectorTitular_txtCliente")).Clear();
driver.FindElement(By.Id("Template_FormControl_ccSelectorTitular_txtCliente")).SendKeys("199655");
driver.FindElement(By.Id("Template_FormControl_ccSelectorTitular_imgBuscarTitular")).Click();
//Waiting for the table to load
WaitUntilElementVisible(By.Id("Tabla_Resumen_Saldos"));
//Saving values for later comparation
ReadOnlyCollection<IWebElement> celdas = driver.FindElements(By.XPath("//*[@class=\"RS_Celda_Contrato\"]"));
//Storing the values in string format
List<string> saldos = new List<string>();
for(int j=3; j<celdas.Count; j = j + 4)
{
saldos.Add(celdas[j].Text.Trim(' '));
}
//Returning to the main window
driver.SwitchTo().Window(driver.WindowHandles[0]);
//Switching to another web to make the comparation of values
TheLogInFibancTest("12345");
//accession the appropiate menu
js.ExecuteScript("doAction('2011', 'prd=1')");
//Waiting for the table to load
var now = DateTime.Now;
var wait = new WebDriverWait(driver, TimeSpan.FromMilliseconds(10000));
wait.PollingInterval = TimeSpan.FromMilliseconds(10000);
wait.Until(wd => (DateTime.Now - now) - TimeSpan.FromMilliseconds(10000) > TimeSpan.Zero);
//Storing the cells values of the table THIS is the table that is readed without the data in the Text propiety
ReadOnlyCollection<IWebElement> celdasFibanc = driver.FindElements(By.XPath("//*[@class=\"RS_Celda_Contrato\"]"));
List<string> saldosFibanc = new List<string>();
for (int j = 2; j < celdasFibanc.Count; j = j + 3)
{
saldosFibanc.Add(celdasFibanc[j].Text.Trim(' '));
}
//checking quatity of values
if (saldosFibanc.Count == saldos.Count)
{
//Comparing results
for (int i =0; i<saldos.Count; i++)
{
if (saldos[i]!=saldosFibanc[i])
{
Assert.IsTrue(false);
}
}
}
}
[编辑2] 我刚刚在Object中意识到,它说单元格的Displayed = false,但这不是真的。。我可以在网上看到它
[编辑3] 试图在单元加载之前等待并切换到帧“区域”,但超时(OpenQA.Selenium.WebDriverTimeoutException:“ 10秒后超时”):
TimeSpan span = TimeSpan.FromSeconds(10);
WebDriverWait wait2 = new WebDriverWait(driver, span);
wait2.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt("area"));
[编辑4] 还尝试使用完整的XPath从单个元素进行读取,但是它也不收取文本属性中的值...
IWebElement prueba = driver.FindElement(By.XPath("/html/body/table/tbody/tr[4]/td/form/table/tbody/tr[4]/td[1]/table[2]/tbody/tr[4]/td[3]"));
答案 0 :(得分:0)
我有一个答案。我的问题是我切换到一个框架,然后尝试切换到同一级别的另一个框架。我需要返回默认框架,然后切换到其他框架
//If there's a popup we close it
if (IsElementPresent(By.Id("contentPop")))
{
driver.SwitchTo().Frame(driver.FindElement(By.Id("contentPop")));
if (IsElementPresent(By.Id("ImageButton1")))
{
driver.FindElement(By.Id("ImageButton1")).Click();
confirmarSegundoCodigoHTML();
}
if (IsElementPresent(By.Id("btnCerrar")) && driver.FindElement(By.Id("btnCerrar")).Displayed)
driver.FindElement(By.Id("btnCerrar")).Click();
driver.SwitchTo().DefaultContent();
driver.SwitchTo().Frame(driver.FindElement(By.CssSelector("frame[name='area']")));
}