Xpath昨天工作正常,我想点击一个按钮。但它今天不工作。当试图运行脚本时,NoSuchElementException即将到来。下面我添加了代码和错误。Xpath昨天是完美的工作,但今天它不工作
HTML代码:
//Clicking on 'Add Customer' button
driver.findElement(By.xpath(".//*[@id='userform']/section[1]/div/div[2]/input")).click();
Thread.sleep(5000);
错误:
的 '添加用户' 按钮<section class="content-header">
<div class="row">
<div class="col-xs-6">
<div class="col-xs-6 text-right">
<a class="btn btn-danger hidden checkdelbtn" data-content="Are you sure to continue?" data-title="Confirm" data-cancel="Cancel" data-confirm="Delete" data-form="userform" href="">
<input class="btn btn-primary" type="button" onclick="window.location.href='http://lab-1.sketchdemos.com/musicshop/stores/musicshop/admin/add-customer.html'" value="Add Customer"/>
</div>
</div>
</section>
试过代码
的源代码
执行上面的代码后,得到这个错误。
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//*[@id='userform']/section[1]/div/div[2]/input"}
Command duration or timeout: 32 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.46.0', revision: '87c69e2',
enter code here
time: '2015-06-04 16:17:10' System info: host: 'SKETCH_QA-02', ip: '10.70.1.32', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_20' Driver info: org.openqa.selenium.firefox.FirefoxDriver
这是因为你的XPath是可怕试试下面这
code
。在这里提出这样的问题之前,你应该多了解一下它。 – acikojevic