gpt4 book ai didi

javascript - 如何从 Protractor 中的随机菜单中获取元素?

转载 作者:行者123 更新时间:2023-12-03 03:39:08 25 4
gpt4 key购买 nike

我是 Protractor 、 typescript 、javascript 的新手......所以,我不知道我到底做错了什么。

网络元素仅返回一个对象,我无法执行单击链接的操作。如何获取链接文本?我尝试使用其他形式,如 id、css、标记名,但由于某种原因,对象在某些时候丢失了。有人遇到这样的问题吗?

//html (which is inside a frame)

<div class="menuLabel" id="menuLabel1"> </div>
<div class="submenubox" id="submenu1"> </div>


<div class="menuLabel" id="menuLabel2">
<table>
<tbody>
<tr>
<td> </td>
<td class="menuText">
<nobr>
<a onmouseover="menuShow(event,'2')" href="javascript:void(null)" class="ml">Example Main Menu</a>
</nobr>
</td>
</tr>
</tbody>
</table>
</div>

<div class="submenubox" id="submenu2">
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="anything">
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr> </tr>
<tr>
<td class="secNav">
<a onmouseover="subMenuShow(event, '2', '1')" ; hoverText='Example Sub Menu' target href="trade/new.action">...</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
//Page object file
export class PageObject {
public mainMenuLink: WebElement = element(By.linkText('Example Main Menu'));
public subMenuLink: WebElement = element(By.linkText('Example Sub Menu'));

async gettingMenu(): Promise<void> {

//Mouse over the Main Menu, once this actions is done, a table with submenu appears
await browser.actions().mouseMove(this.mainMenuLink);

//Clicking on the submenu link
await browser.actions().mouseMove(this.subMenuLink);
await browser.actions().click(this.subMenuLink);

}
}

最佳答案

您缺少 .perform() 调用。来自官方docs :

Creates a sequence of user actions using this driver. The sequence will not be scheduled for execution until webdriver.ActionSequence#perform is called.

尝试:

 browser.actions().mouseMove(this.subMenuLink).click().perform();

关于javascript - 如何从 Protractor 中的随机菜单中获取元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45714385/

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