我是硒的新手请帮忙。整个代码:
<document>
<html class="ext-strict ext-strict x-viewport" lang="en" style="">
<head>
<body id="ext-gen3" class="ServiceDeskPage sfxConsole ext-gecko ext-gecko3 sfdcBody brandQuaternaryBgr x-border-layout-ct" onfocus="if(this.bodyOnFocus)bodyOnFocus();" onload="if(this.bodyOnLoad)bodyOnLoad();" onbeforeunload="if(this.bodyOnBeforeUnload){var s=bodyOnBeforeUnload();if(s)return s;}" onunload="if(this.bodyOnUnload)bodyOnUnload();">
<div id="ServiceDeskHeader" class=" x-panel sd_header x-border-panel x-panel-noborder" style="left: 0px; top: 0px; width: 1366px;">
<div id="serviceDeskFooter" class=" sd_footer widget_right_aligned x-border-panel x-hide-display x-box-layout-ct" style="height: 35px; background: rgb(167, 169, 172) none repeat scroll 0% 0%;">
<div id="hotkey_focus_effect" style="display:none"/>
<div id="servicedesk" class=" miniviewtab_enabled x-border-panel x-border-layout-ct" style="left: 0px; top: 75px; width: 1366px; height: 202px;">
<!-- Main Body Starts Here -->
<form id="sessiontimeout" onsubmit="if (window.ffInAlert) { return false; }" name="sessiontimeout" method="post">
<a class="navSkipLink zen-skipLink zen-assistiveText" href="#skiplink">Skip to main content</a>
<form name="HistoryForm" method="POST" action="">
<div id="auraElementContainer" class="hiddenAuraElementContainer">
<div id="ext-comp-1002" class="x-tip" style="position: absolute; z-index: 20002; visibility: hidden; display: none;">
<div id="ServiceDeskHeader-xsplit" class="x-layout-split x-layout-split-north x-splitbar-v-custom-logo x-splitbar-disabled" style="visibility: visible; left: 0px; top: 77px; width: 1366px;">
<div id="ext-gen35" class="dd-drop-indicator" style="visibility: hidden;"/>
<div id="ext-gen51" class="dd-drop-indicator" style="visibility: hidden;"/>
<div id="ext-gen55" class=" x-unselectable x-splitbar-proxy x-splitbar-proxy-h" style="-moz-user-select: none;"/>
<div id="ext-gen63" class="x-dd-drag-proxy x-dd-drop-nodrop" style="position: absolute; z-index: 15000; visibility: hidden; left: -10000px; top: -10000px;">
<div id="ext-gen86" class="dd-drop-indicator" style="visibility: hidden;"/>
<div id="undefinedHover" class="individualPalette lookupHoverDetail lookupHoverDetailLoading lookupHoverDetailOverridable">
<iframe title="sessionserver" style="position: absolute; top: -999px; left: -999px;" src="https://test.salesforce.com/login/sessionserver202.html"/>
<div id="ext-gen113" class="x-shadow" style="z-index: 14999; left: 1px; top: 40px; width: 258px; height: 240px; display: none;">
<div id="navigator-sbmenu" class="x-menu x-menu-floating x-layer x-hide-offsets" style="position: absolute; z-index: 15000; visibility: hidden; left: -10000px; top: -10000px; width: 250px;">
<a id="ext-gen94" class="x-menu-focus" tabindex="-1" onclick="return false;" href="#"/>
<ul id="ext-gen95" class="x-menu-list" style="height: 224px;">
<li id="x-menu-el-nav-tab-0" class="x-menu-list-item">
<li id="x-menu-el-nav-tab-1" class="x-menu-list-item">
//On mouse click this element should be selected out of the list items mentioned.
<**a id="nav-tab-1" class="x-menu-item accountMru standardObject sd-nav-menu-item" href="#" unselectable="on" hidefocus="true"**>
</li>
<li id="x-menu-el-nav-tab-2" class="x-menu-list-item">
<li id="x-menu-el-nav-tab-3" class="x-menu-list-item">
<li id="x-menu-el-nav-tab-4" class="x-menu-list-item">
<li id="x-menu-el-nav-tab-5" class="x-menu-list-item">
<li id="x-menu-el-nav-tab-6" class="x-menu-list-item">
<li id="x-menu-el-nav-tab-7" class="x-menu-list-item">
</ul>
</div>
</body>
</html>
</document>
如何为Bold中突出显示的元素选择xpath?我尝试了很多例子,但遗憾的是没有一个像预期的那样工作。 任何帮助都会很棒。
答案 0 :(得分:0)
这个元素的xpath实际上非常简单
driver.findElement(By.xpath("//a[@id=nav-tab-1]");
或者,您可以使用By.id选择器来选择元素
driver.findElement(By.id("nav-tab-1"));
要触发javascript下拉列表创建并等待加载子菜单,您可以使用以下内容:
driver.findElement(By.id("x-menu-el-nav-tab-1")).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocatedBy(By.id("nav-tab-1"))).click();