当前位置: 首页 > 知识库问答 >
问题:

Selenium驱动程序在运行以下脚本时引发错误

郗福
2023-03-14

Html代码:

<div class="leftpan-button leftpan-button-active" ui-sref="main.poList({status: 'Finalize'})" ui-sref-active="leftpan-button-active" title="" href="#/main/po/Finalize">Finalize <!-- ngIf: vm.statusCount.PendingCount --><span class="badge pull-right ng-scope" style="background-color: rgb(255, 106, 0);" ng-if="vm.statusCount.PendingCount"></span><!-- end ngIf: vm.statusCount.PendingCount --></div>
Status list :<div class="panel-body tagList"><div class="leftpan-button leftpan-button-active" ui-sref="main.poList({status: 'Finalize'})" ui-sref-active="leftpan-button-active" title="" href="#/main/po/Finalize">Finalize <!-- ngIf: vm.statusCount.PendingCount --><span class="badge pull-right ng-scope" style="background-color: rgb(255, 106, 0);" ng-if="vm.statusCount.PendingCount"></span><!-- end ngIf: vm.statusCount.PendingCount --></div><div class="leftpan-button" ui-sref="main.poList({status: 'Pending for Approval'})" ui-sref-active="leftpan-button-active" title="" href="#/main/po/Pending%20for%20Approval">Pending for approval <!-- ngIf: vm.statusCount.PendingCount --><span class="badge pull-right ng-binding ng-scope" style="background-color: rgb(255, 106, 0);" ng-if="vm.statusCount.PendingCount" ng-bind="vm.statusCount.PendingCount">11</span><!-- end ngIf: vm.statusCount.PendingCount --></div><div class="leftpan-button" ui-sref="main.poList({status: 'Draft'})" ui-sref-active="leftpan-button-active" title="" href="#/main/po/Draft">Upcoming <!-- ngIf: vm.statusCount.UpcomingCount --><span class="badge pull-right ng-binding ng-scope" style="background-color: rgb(255, 106, 0);" data-ng-if="vm.statusCount.UpcomingCount" ng-bind="vm.statusCount.UpcomingCount">10</span><!-- end ngIf: vm.statusCount.UpcomingCount --></div><div class="leftpan-button" ui-sref="main.poList({status: 'Approved'})" ui-sref-active="leftpan-button-active" title="" href="#/main/po/Approved">Approved <!-- ngIf: vm.statusCount.ApprovedCount --><span class="badge pull-right ng-binding ng-scope" style="background-color: rgb(255, 106, 0);" data-ng-if="vm.statusCount.ApprovedCount" ng-bind="vm.statusCount.ApprovedCount">38</span><!-- end ngIf: vm.statusCount.ApprovedCount --></div><div class="leftpan-button" ui-sref="main.poList({status: 'Rejected'})" ui-sref-active="leftpan-button-active" title="" href="#/main/po/Rejected">Rejected <!-- ngIf: vm.statusCount.RejectedCount --><span class="badge pull-right ng-binding ng-scope" style="background-color: rgb(255, 106, 0);" data-ng-if="vm.statusCount.RejectedCount" ng-bind="vm.statusCount.RejectedCount">9</span><!-- end ngIf: vm.statusCount.RejectedCount --></div></div>
 driver.findElement(By.xpath("//*[@id='statusList']/div/div[1]").click();
driver.findElement(By.cssSelector("#statusList > div > div.leftpan-button.leftpan-button-active")).click();
 driver.findElement(By.linkText("Finalize")).click();
WebDriverWait wait = new WebDriverWait(driver, 30);// 1 minute
            wait.until(ExpectedConditions.visibilityOfElementLocated (By.cssSelector("#statusList > div > div.leftpan-button.leftpan-button-active")));

结果:

在com.example.tests.finalizepo.main(finalizepo.java:41)的org.openqa.selenium.support.ui.webdriverwait.timeoutexception(webdriverwait.java:80)直到(fluentwait.java:261)由:org.openqa.selenium.nosuchelementexception:没有这样的元素:无法定位元素:{“method”:“CSS selector”,“selector”:“#statuslist>div

div.leftpan-button.leftpan-button-active“}(会话信息:chrome=50.0.2661.102)(驱动程序信息:chromedriver=2.21.371459(36D3D7F660FF2BC1BF28A75D1CDABED0983E7C4),Platform=Windows NT 6.3x86_64)(警告:服务器未提供任何stacktrace信息)命令持续时间或超时:0毫秒有关此错误的文档,请访问:http://seleniumhq.org/exceptions/no_such_element.html构建信息:版本:'2.53.0',修订:'35AE25B',时间:6-03-15 16:57:40'系统信息:host:'admin',IP:'192.168.51.205',OS.name:'Windows 8.1',OS.arch:'amd64',OS.version:'6.3',java.version:'1.8.0_60'驱动程序信息:org.openqa.selenium.chrome.chromeDriver功能[{applicationcacheenabled=false,rotatable=false,mobileemulationenabled=false,chrome={\users\bayapr~1\appdata\local\temp\scoped_dir1612_1332},takesheapsnapshot=true,databaseenabled=false,handlesalerts=true,hasTouchScreen=false,version=50.0.2661.102,platform=win8_1,browserconnectionenabled=false,nativeevents=true,acceptsslcerts=true,locationcontextenabled=true,webstorageenabled=true,browsername=chrome,takesscreenshot=true,javascriptenabled=true,csssselectorsenabled=true,csssselectorsenabled=true,csssselectorsenabled=true}]ect.generatedConstructorAccessor8.newInstance(未知来源)在sun.reflect.delegatingConstructorAccessorimpl.newInstance(未知来源)在java.lang.reflect.constructor.newInstance(未知来源)在org.openqa.selenium.remote.errorhandler.createThrowable(未知来源)在org.openqa.selenium.remote.errorhandler.createThrowable(errorhandler.java:206),在webdriver.java:363)位于org.openqa.selenium.remote.remot在org.openqa.selenium.by$bycsssdriver.java:492),org.openqa.selenium.remote.remoteWebdriver.findelement(by.java:430),org.openqa.selenium.remote.remoteWebdriver.findelement(remoteWebdriver.java:355),org.openqa.selenium.support.ui.expectedconditions.findelement java:205)在org.openqa.selenium.support.ui.expectedconditions$7。apply(expectedconditions.java:1)在org.openqa.selenium.support.ui.fluentwait.tow(fluentwait.java:238)...还有1个

共有1个答案

东郭瀚玥
2023-03-14

尝试下面的代码:

WebDriverWait wait = new WebDriverWait(driver, 9);
WebElement el = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.leftpan-button.leftpan-button-active[href$='/main/po/Finalize']")));

driver.findElement(By.cssSelector("div.leftpan-button.leftpan-button-active[href$='/main/po/Finalize']")).click();

告诉我发生了什么。

 类似资料:
  • 问题内容: 在硒测试中出现以下错误 我所做的是 环境: Firefox v47.0 Webdriver 3.0.0-beta2 问题答案: 这是完全可以预期的。没有GeckoDriver(木偶)的发行版支持该类。这是Mozilla团队开发Marionette的首要任务之一。

  • 尝试使用IE驱动程序在Luna Eclipse中运行脚本,但出现以下错误: 线程“main”org . open QA . selenium . remote . unreachablebrowserexception中出现异常:无法启动新会话。可能的原因是远程服务器的地址无效或浏览器启动失败。下面是尝试运行的代码: }

  • 问题内容: 我正在尝试运行一个ruby文件,该文件将使用seleniumwebdriver启动chrome驱动程序。我有selenium独立服务器2.35.0。和chromedriver可执行文件已安装。我正在通过运行服务器来启动 两个会话正在启动,chrome驱动程序无法启动。 这是在我使用以下文件运行文件之后 我对此并不陌生,无法找出问题所在。而且,我也试图让它无头运行,所以我正在运行Xvfb

  • 我试图运行一个ruby文件,这将启动chrome驱动程序使用selenium WebDriver。我有selenium独立服务器2.35.0。和chromedriver可执行文件安装。我通过运行来启动服务器, 这是在我使用 我对此很陌生,不知道哪里出了问题。我也试图无头运行它,所以我有Xvfb运行。有人能帮我指出我犯的错误并启动chromedriver吗? 更新: 谁能帮我弄清楚出了什么问题吗?

  • null 所以目前一切都在无头模式下工作。但是我需要在一个没有GUI的linux服务器上运行这个python脚本(因此需要headless模式)。出于某种原因,我所有无头运行的尝试都导致selenium web驱动程序在初始化时超时。 以下是回溯: 文件“C:\users\xuser\desktop\bomwebservice\backend\code\firefoxstarter.py”,第51

  • 我正在使用硒构建UI自动化测试,我想使用Internet Explorer浏览器测试我们的产品。我正在尝试使用Selenium 3.4创建InternetExplorerDriver。 但是当我将选项设置为在私人模式下运行时,IE浏览器无法启动。我设置的选项是: 代码运行在VS 2017,windows 10,64位,并尝试运行32位的Internet explorer驱动程序。