Que:如何点击下拉列表中的“Logout”
<tr id="dijit_MenuItem_55" class="dijitReset dijitMenuItem" dojoattachevent="onmouseenter:_onHover,onmouseleave:_onUnhover,ondijitclick:_onClick" tabindex="-1" role="menuitem" dojoattachpoint="focusNode" aria-labelledby="dijit_MenuItem_55_text dijit_MenuItem_55_accel" style="-moz-user-select: none;" widgetid="dijit_MenuItem_55">
<tr id="dijit_MenuItem_56" class="dijitReset dijitMenuItem" dojoattachevent="onmouseenter:_onHover,onmouseleave:_onUnhover,ondijitclick:_onClick" tabindex="-1" role="menuitem" dojoattachpoint="focusNode" aria-labelledby="dijit_MenuItem_56_text dijit_MenuItem_56_accel" style="-moz-user-select: none;" widgetid="dijit_MenuItem_56">
<td class="dijitReset dijitMenuItemIconCell" role="presentation">
<td id="dijit_MenuItem_56_text" class="dijitReset dijitMenuItemLabel" dojoattachpoint="containerNode" colspan="2">Logout</td>
我试过
driver.findElement(By.id("processPortalUserDropdown")).click();
driver.findElement(By.linkText("Logout")).click();
OR
driver.findElement(By.cssSelector("Logout")).click();
但它不起作用
NOte:
1.我无法使用id = dijit_MenuItem_56_text,因为它会在每次登录时或在网站中执行任何功能后动态更改。
2.我试过
new Select(driver.findElement(By.id("processPortalUserDropdown"))).selectByVisibleText("Logout" );
但它显示错误消息为
FAILED: testQTO01
org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "div"
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:15:02'
System info: host: 'TSSGMSL060', ip: '10.56.40.138', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_40'
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.Select.<init>(Select.java:46)
at Com.Tss.Qto.QTO01.testQTO01(QTO01.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
请有人给我一个解决方案吗?..这将是很好的帮助.. 提前感谢。
答案 0 :(得分:1)
尝试
new Select(driver.findElement(By.id("processPortalUserDropdown"))).selectByVisibleText("Logout")
答案 1 :(得分:0)
尝试driver.findElement(By.id(“dijit_MenuItem_56_text”))。click();
答案 2 :(得分:0)
试试这个。
Actions builder = new Actions(driver);
builder.Click(driver.findElement(By.id("processPortalUserDropdown")))
.Click(driver.findElement(By.linkText("Logout")))
.Click()
.Perform();
答案 3 :(得分:0)
尝试这个定位器// td [contains(text(),'Logout')]
oASelFW.driver.findElement(By.xpath( “// TD [含有(文本(), '退出')]”))上单击();