webdriver的找不到元素

问题描述 投票:1回答:1

我无法找到硒元素(下文ID),即使它在后“搜索”按钮,点击成功(使用Selenium)具有URL如下的前一页的就是在HTML源代码页面可见:

String url="https://sjobs.brassring.com/1033/ASP/TG/cim_advsearch.asp?partnerid=25314&siteid=5290";
driver.get(url);
if(driver.findElements(By.id("submit1")).size() != 0)
    driver.findElement(By.id("submit1")).click(); // clicking on 'Search' button
if(driver.findElements(By.id("ctl00_MainContent_GridFormatter_YUIGrid")).size() != 0)      
    System.out.println("FOUND!");

String pageSource= driver.getPageSource();

“找到了!”从来没有显示,也没有pageSource包含与上述ID的元素。我使用的硒2.3.3,并与IE,Chrome和火狐webdrivers的最新版本的测试。可能有人请帮忙吗?谢谢。

约1/3从目标页面的底部是以下内容(第三行是该ID的位置):

<div id="ctl00_MainContent_GridFormatter_datatable" class="datatable">
<div id="THeadersDiv" style="display:none;">
<table id="ctl00_MainContent_GridFormatter_YUIGrid" class="basicGrid" border="0"> <!-- this is the element in question -->
selenium webdriver
1个回答
0
投票

我想我得到了它。我相信,司机无法找到的元素,因为有两个具有相同ID的两个元素。 (这是可怕的网页代码)。我看了看代码的其余部分,它看起来像两个要素也有着相同的类,并且是与班上只有两个元素。

因此,我认为,做一个By.className(".basicGrid") should work

© www.soinside.com 2019 - 2024. All rights reserved.