gpt4 book ai didi

java - 无法定位元素

转载 作者:行者123 更新时间:2023-12-01 11:55:20 24 4
gpt4 key购买 nike

我正在使用 Selenium Webdriver 用 Ja​​va 进行编码。我在页面中找不到链接文本“许可证管理器”。当我尝试切换到名为 "text" 的框架时。 Selenium 无法找到名为“text”的框架,请帮忙。

这是我的代码:

d.switchTo().frame("enterpriseStatus");
d.findElement(By.id("bannerSettingsButton")).click();//settings button
d.manage().timeouts().pageLoadTimeout(15000, TimeUnit.SECONDS);
d.switchTo().window("name=text");//This is where something goes wrong
d.findElement(By.linkText("License Manager")).click();

这是框架来源:

<body>
<div class="tablecontentarea-div" style="width: 90%;">
<table class="tabletitlebar">
<tr>
<td>
<span class="titlepage">Settings</span>
</td>
</tr>
</table>
<div class="tablecontentpanel" style="padding-top: 15px;">
<table style="width:100%" summary="">
<tr>
<td style="width:50%; padding-right:7px; vertical-align: top;">
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/servers_32x32.png"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Device Management</div>
<div>
Add, manage, configure and delete devices.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/GettingStarted.do?actionName=main">Getting Started</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/DeviceListServlet">All Devices</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/ArrayAssignment.do?actionName=listAssignments">Manage Agent Assignments</a></td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/PolicyServlet?state=listPolicies">Policies</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/DeviceGroupList.do?actionName=showMainPage">Device Groups</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/FilersAssignment.do?actionName=viewNetAppFilerAssignment&filerAgentTypeID=401">NetApp Operations Manager</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/ClusterAssignment.do?actionName=listAssignments">Virtualization (Assign ESX Hosts)</a></td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/ServerSetup.do?sectionName=Arrays">Server Setup: Arrays</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/ServerSetup.do?sectionName=Database">Server Setup: Databases</a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/alerting_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Rules &amp; Alerting</div>
<div>
Setup rules that can perform a variety of actions, including running scripts.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/RulesList.do?actionName=listRules">All Rules</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/RulesList.do?actionName=listRules&ruleTypeId=3">Threshold Rules</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/RulesList.do?actionName=listRules&ruleTypeId=2">Windows Event Log Rules</a></td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/RulesList.do?actionName=listRules&ruleTypeId=6">Asset Change Rules</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/RulesList.do?actionName=listRules&ruleTypeId=5">Scheduled Rules</a></td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/ServerSetup.do?sectionName=Real Time">Server Setup: Real Time</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/ScriptList.do?actionName=showMainPage">Scripts</a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/file_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Files</div>
<div>
Configure file analysis, file rules, assign shares to agents.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/RulesList.do?actionName=listRules&ruleTypeId=1">File Analysis Rules</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/RulesList.do?actionName=listRules&ruleTypeId=4">Directory Analysis Rules</a></td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/FileTypeGroupsList.do?actionName=showMainPage">File Type Groups</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/NasSharesAssignment.do">Assign Remote Shares</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/LocalSharesAssignment.do">Assign Local Shares</a></td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/ServerSetup.do?sectionName=File Analysis">Server Setup: File Analysis</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/VmSharesAssignment.do">Discover VM Targets</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/FARepServlet">File Repository</a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/user_accounts_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Users</div>
<div>
Add, edit, and remove user accounts.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/UserList.do?actionName=showMainPage">Manage Users</a></td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/ServerSetup.do?sectionName=User Authentication">Server Setup: User Authentication</a></td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&nbsp;</td>
<td valign="top">&nbsp;</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td style="width:50%; padding-left:8px; vertical-align: top;">
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/server_profiler_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Storage Manager Server</div>
<div>
Configure and view information about your server.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/ServerSetup.do">Server Setup: All</a></td>
</tr>
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/AboutDisplay.do?actionName=displayLicense">About</a></td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/ServerSetup.do?sectionName=E-mail">Server Setup: E-mail</a></td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/DataRetentionPolicies.do">Data Retention</a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/web_update_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Updates &amp; Upgrades</div>
<div>
Upload new modules and upgrade your agents and pollers.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/ModuleList.do?actionName=showMainPage">Upload Modules</a></td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/ModulePush.do">Upgrade Agents</a></td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&nbsp;</td>
<td valign="top">&nbsp;</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/reports_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">GUI &amp; Reporter</div>
<div>
Configure GUI and Reporting behavior.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/ServerSetup.do?sectionName=Reporter">Server Setup: Reporter</a></td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/ServerSetup.do?sectionName=GUI">Server Setup: GUI</a></td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&nbsp;</td>
<td valign="top">&nbsp;</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/license_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">License Summary</div>
<div>
View your license type and number of storage modifiers.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="/LicenseManager.do?actionName=showLicenseManager">License Manager</a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/Icon.Thwack.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">thwack Community</div>
<div>
Import shared application templates posted on thwack, a community site for Solarwinds users. thwack features helpful devices, tips and downloads from over 20,000 network engineers.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&#187;&nbsp;</td>
<td valign="top"><a href="http://thwack.com/forums/63/profiler/185/storage/" target="_blank">Storage thwack Forum</a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</body>

最佳答案

要切换到窗口,您必须使用 WindowsHandle。

如果您正在处理具有不同标题的窗口,您可以尝试使用以下功能。

private String mainWindowsHandle; // Stores current window handle
public static boolean swithToWindow(WebDriver driver,String title){
mainWindowsHandle = driver.getWindowHandle();
Set<String> handles = driver.getWindowHandles(); // Gets all the available windows
for(String handle : handles)
{
driver.switchTo().window(handle); // switching back to each window in loop
if(driver.getTitle().equals(title)) // Compare title and if title matches stop loop and return true
return true; // We switched to window, so stop the loop and come out of funcation with positive response
}
driver.switchTo().window(mainWindowsHandle); // Switch back to original window handle
return false; // Return false as failed to find window with given title.
}

关于java - 无法定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28499221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com