gpt4 book ai didi

javascript - java 中的 selenium 无法点击 href ="javascript:void(0);"

转载 作者:行者123 更新时间:2023-11-30 20:26:03 24 4
gpt4 key购买 nike

这是我正在处理的代码。我正在尝试点击子菜单。

<ul class="accordion">
<li id="one1" class="files">
<a href="#one1">Accounts</a>
<ul class="sub-menu">
<li>

<a href="#one1" onClick="loadTabv2('accounts/LoadAccountGroupMaster',
'Account Group','accounts_account_group');"><img src="layouts/static/image/micons/account_group.png">Account Group</a>

<a href="#one1" onClick="loadTabv2('accounts/AccountingPeriod',
'Accounting Period','account_accounting_period');"><img src="layouts/static/image/micons/accounting_period.png">Accounting Period</a>

<a href="javascript:void(0);" onClick="loadTab('accounts/LoadAccountMaster',
'Account Master','account_account_master');"> <img src="layouts/static/image/micons/account_master.png">Account Master</a>

<a href="javascript:void(0);" onClick="loadTab('accounts/AccountsDashboard',
'Accounts Dashboard','accounts_dashboard');"> <img src="layouts/static/image/micons/accounts_dashboard.png">Accounts Dashboard</a>

<a href="javascript:void(0);" onClick="loadTab('accounts/AccountSettings',
'Account Settings','accounts_account_settings');"> <img src="layouts/static/image/micons/account_settings.png">Account Settings</a>

我正在尝试点击帐户组和帐户仪表板。它们都没有收到点击。尝试了此代码但失败了。

List<WebElement> submenus=driver.findElements(By.xpath("//li[@id='one1']//li//a"));
for (WebElement submenu: submenus) {
System.out.println("values of each submodule :
"+submenu.getAttribute("innerHTML"));
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
if (submenu.getAttribute("innerHTML").contains("Accounts Dashboard")) {
submenu.click();
break;
}

最佳答案

  1. 单击“帐户仪表板”

    Accounts Dashboard 的 href 中的

    javascript:void(0); 返回未定义。当尝试点击这样的链接时,会执行点击,但不会获取任何方法返回值。这给人一种没有执行点击的印象。使用

    JavascriptExecutor jsexec = (JavascriptExecutor) 驱动程序;
    jsexec.executeScript("arguments[0].click();", submenu);

    代替 submenu.click();

  2. 点击帐户组

    Selenium 单击此链接,href #one1 将附加到 URL 以确认执行了单击。

关于javascript - java 中的 selenium 无法点击 href ="javascript:void(0);",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50916937/

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