gpt4 book ai didi

xpath - 无法使用selenium找到元素,在MVC中开发的代码

转载 作者:行者123 更新时间:2023-12-02 11:38:00 25 4
gpt4 key购买 nike

attached the code 我无法使用 Xpath 找到该元素。代码是在MVC框架下开发的,代码来自partial-view。请检查所附图片和帮助

<html class=" js flexbox no-touch backgroundsize boxshadow  
csstransforms" style="">
<head>
<body>
<header class="header header-waterfall affix-top">
<div class="menu-wrapper pull-left" role="navigation">
<ul class="nav nav1" role="menubar">
<li role="menuitem">
<a href="#">
<span class="icon icon-lg">menu</span>
</a>
<div id="menu_nav" class="mega-menu" role="menu" aria-hidden="true"
style="">
</li>
</ul>
</div>
<div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pull-left">
<ul class="nav nav-list pull-right" style="padding: 6px 0px; cursor:
pointer;">
</header>

尝试过 spanli 角色等。但是,我遇到错误的最多次数是,没有交互。

FAILED: testCheckFarmerData org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//ul[@class= 'nav nav 1']/li/a/span"} Command duration or timeout: 30.13 seconds

最佳答案

您应该尝试使用WebDriverWait,如下所示:-

WebDriverWait wait = new WebDriverWait(driver, 10);
el = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("menu")));
el.click();

Edited1 :- 您可以使用 JavascriptExecutor 执行click,如下所示:-

WebDriverWait wait = new WebDriverWait(driver, 10);
el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("menu")));
((JavascriptExecutor)driver).executeScript("arguments[0].click()", el);

已编辑2:-

WebDriverWait wait = new WebDriverWait(driver, 10); 
el = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//ul[@cla‌​ss='nav nav1']/descendant::span[contains(.,'menu')]")));
((JavascriptExecutor)driver).executeScript("arguments[0].click()", el);

希望有帮助..:)

关于xpath - 无法使用selenium找到元素,在MVC中开发的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38452641/

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