使用:wEBDRIVER版本selenium-2.44.0
环境:Windows 7教授
USE:Eclipse Kepler Service Release 2 Build id:20140224-0627
LANGUAGE:java - version:' 1.7.0_71'
<ul class="tree-default">
<li class="open" rel="package" id="package_15245" depth="1">
<a onclick="getLearningPackageInfo(15245);" id="packageNodeName_15245" style="background-image:url(/suite/images/folder2.gif);" href="#">Unit 1</a>
<ul id="parent_15245" style="list-style-type:none;">
<li class="open" rel="package" id="package_15402" depth="2">
<a onclick="getLearningPackageInfo(15402);" id="packageNodeName_15402" style="background-image:url(/suite/images/folder2.gif);" href="#">
<div class="nonTitleDivs">Lesson 1</div>
<div class="titleDivs" style="display:none;">Lesson 1: Understanding Simple Graphs</div>
</a>
<ul id="parent_15402">
<li class="leaf" rel="page" id="page_36934" depth="2">
<a class="clicked" id="pageNodeName_36934" style="background-image:url(/suite/images/text.gif);" onclick="getPageContentAreas(36934, 15402);" href="#">Page 1</a>
</li>
<li class="leaf" rel="page" id="page_36938" depth="2">
<a id="pageNodeName_36938" style="background-image:url(/suite/images/text.gif);" onclick="getPageContentAreas(36938, 15402);" href="#">Page 2</a>
driver = new FirefoxDriver();
执行以下声明:
driver.manage().timeouts().implicitlyWait(59, TimeUnit.SECONDS);
driver.findElement(By.id("pageNodeName_36938")).click(); // failed here - see error messages below
错误信息: org.openqa.selenium.NoSuchElementException:无法找到元素:{&#34;方法&#34;:&#34; id&#34;,&#34;选择器&#34;:&#34; pageNodeName_36938&#34;} 命令持续时间或超时:59.14秒 有关此错误的文档,请访问:http://seleniumhq.org/exceptions/no_such_element.html 构建信息:版本:&#39; 2.44.0&#39;,修订版:&#39; 76d78cf&#39;,时间:&#39; 2014-10-23 20:03:00&#39; 系统信息:主持人:&#39; LT-JRCHEN&#39;,ip:&#39; 10.128.253.14&#39;,os.name:&#39; Windows 7&#39;,os.arch:&# 39; amd64&#39;,os.version:&#39; 6.1&#39;,java.version:&#39; 1.7.0_71&#39; 会议编号:ca3454c1-81c8-48ba-b83c-9e058af768cc 驱动程序信息:org.openqa.selenium.firefox.FirefoxDriver
执行以下语句:使用onClick事件
driver.manage().timeouts().implicitlyWait(59, TimeUnit.SECONDS);
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("getPageContentAreas(36938, 15402)"); // failed here also - see error messages below
错误信息: getPageContentAreas未定义 命令持续时间或超时:71毫秒
有什么想法吗?
感谢。 佳乐
答案 0 :(得分:0)
您确定使用id("pageNodeName_36938")
的ID不是动态的吗?
看起来这个号码'36938'每次都会改变,这就是为什么你得到NoSuchElementException
您需要找到比ID
更好的定位器尝试使用xpath定位器 -
driver.findElement(By.xpath("//a[text()='Page 2'])).click();