<legend id='Pd2hb'><style id='Pd2hb'><dir id='Pd2hb'><q id='Pd2hb'></q></dir></style></legend>
    <bdo id='Pd2hb'></bdo><ul id='Pd2hb'></ul>
  • <i id='Pd2hb'><tr id='Pd2hb'><dt id='Pd2hb'><q id='Pd2hb'><span id='Pd2hb'><b id='Pd2hb'><form id='Pd2hb'><ins id='Pd2hb'></ins><ul id='Pd2hb'></ul><sub id='Pd2hb'></sub></form><legend id='Pd2hb'></legend><bdo id='Pd2hb'><pre id='Pd2hb'><center id='Pd2hb'></center></pre></bdo></b><th id='Pd2hb'></th></span></q></dt></tr></i><div id='Pd2hb'><tfoot id='Pd2hb'></tfoot><dl id='Pd2hb'><fieldset id='Pd2hb'></fieldset></dl></div>

      1. <tfoot id='Pd2hb'></tfoot>

      2. <small id='Pd2hb'></small><noframes id='Pd2hb'>

        为什么我的测试抛出异常 - 无法在 webdriver 中定位元素?

        时间:2023-05-28
        <i id='SMPXV'><tr id='SMPXV'><dt id='SMPXV'><q id='SMPXV'><span id='SMPXV'><b id='SMPXV'><form id='SMPXV'><ins id='SMPXV'></ins><ul id='SMPXV'></ul><sub id='SMPXV'></sub></form><legend id='SMPXV'></legend><bdo id='SMPXV'><pre id='SMPXV'><center id='SMPXV'></center></pre></bdo></b><th id='SMPXV'></th></span></q></dt></tr></i><div id='SMPXV'><tfoot id='SMPXV'></tfoot><dl id='SMPXV'><fieldset id='SMPXV'></fieldset></dl></div>

          <legend id='SMPXV'><style id='SMPXV'><dir id='SMPXV'><q id='SMPXV'></q></dir></style></legend>
          1. <tfoot id='SMPXV'></tfoot>
              • <bdo id='SMPXV'></bdo><ul id='SMPXV'></ul>

                • <small id='SMPXV'></small><noframes id='SMPXV'>

                    <tbody id='SMPXV'></tbody>
                  本文介绍了为什么我的测试抛出异常 - 无法在 webdriver 中定位元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  package testproject;
                  
                  import org.openqa.selenium.By;
                  import org.openqa.selenium.WebDriver;
                  import org.openqa.selenium.WebElement;
                  import org.openqa.selenium.firefox.*;
                    public class mytestclass {
                      public static void main(String[] args) {
                         WebDriver Driver = new FirefoxDriver();
                          Driver.get("https://www.gmail.com/");
                           WebElement wb= Driver.findElement(By.name("Email"));
                           wb.sendKeys("sweta");
                           WebElement wb1= Driver.findElement(By.name("Passwd"));
                           wb1.sendKeys("123456");
                           WebElement wb2= Driver.findElement(By.id("signIn"));
                           wb2.click();
                           WebElement wb3= Driver.findElement(By.xpath(".//*[@id='gb']/div[1]/div[1]/div[2]/div[5]/div[1]/a"));
                           wb3.click();
                           WebElement wb4= Driver.findElement(By.id("gb_71"));
                           wb4.click();
                     }
                  }
                  

                  当我执行此代码时,一切都很好,直到我希望单击登录按钮.我得到了例外,它说线程main" org.openqa.selenium.NoSuchElementException 中的异常:无法定位元素:{method":xpath",selector":.//*[@id='gb']/div[1]/div[1]/div[2]/div[5]/div[1]/a"} 但是当我尝试使用 fierbug 定位它时,它工作正常.在上述代码中,我更改了电子邮件 ID 和密码以确保电子邮件安全.

                  When i am executing this code everything is going fine till the point where i want the sign in button to be clicked. I am getting exception which says that Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//*[@id='gb']/div[1]/div[1]/div[2]/div[5]/div[1]/a"} but when i am trying to locate it using fierbug its working fine. In the above mentioned code i changed the email id and password to keep the email safe.

                  我已经在 stakwave 上发布了另一个程序的问题,所以如果你可以的话,请看看这个链接 -webdriver 无法点击 firefox 中的超链接

                  I was facing problem with one more program which i already posted on stakwave so if u can then please have a look at this link-webdriver is not able to click on a hyperlink in firefox

                  推荐答案

                  我遇到了类似的问题,设置超时后问题解决.

                  I faced similar problem, issue resolved after setting timeout.

                  Webdriver driver = new FirefoxDriver();
                  driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
                  

                  不知道超时在这里的作用是什么.

                  Not sure whats the role of timeout here though.

                  这篇关于为什么我的测试抛出异常 - 无法在 webdriver 中定位元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:maven pom.xml 如何识别非标准项目结构中的 testng 测试用例? 下一篇:Selenium:如何通过 executeScript() 发送可变字符串

                  相关文章

                  1. <tfoot id='7v945'></tfoot>
                    <legend id='7v945'><style id='7v945'><dir id='7v945'><q id='7v945'></q></dir></style></legend>
                  2. <i id='7v945'><tr id='7v945'><dt id='7v945'><q id='7v945'><span id='7v945'><b id='7v945'><form id='7v945'><ins id='7v945'></ins><ul id='7v945'></ul><sub id='7v945'></sub></form><legend id='7v945'></legend><bdo id='7v945'><pre id='7v945'><center id='7v945'></center></pre></bdo></b><th id='7v945'></th></span></q></dt></tr></i><div id='7v945'><tfoot id='7v945'></tfoot><dl id='7v945'><fieldset id='7v945'></fieldset></dl></div>
                      <bdo id='7v945'></bdo><ul id='7v945'></ul>

                    <small id='7v945'></small><noframes id='7v945'>