sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) using findElement(By.className()) through Selenium and Java

后端 未结 1 1778
感情败类
感情败类 2020-12-21 19:21

When I execute the following code:

driver.findElement(By.className(\"qview-product-name\")).click();

I get the following error



        
相关标签:
1条回答
  • 2020-12-21 19:47

    There are a couple of things you need to take care of:

    • By.className("qview-product-name") refers to the parent <dd> tag and perhaps is not the desired element you want to click. Rather your usecase must be to click on the <a href="Link_here"_blank">Title</a> element.
    • As per best practices, while invoking click() you need to induce you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

    • linkText:

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("Title"))).click();
      
    • cssSelector:

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("dd.qview-product-name a[href='Link_here']"))).click();
      
    • xpath:

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//dd[@class='qview-product-name']//a[@href='Link_here' and text()='Title']"))).click();
      

    Additional Considerations

    Ensure that:

    • JDK is upgraded to current levels JDK 8u222.
    • Selenium is upgraded to current levels Version 3.141.59.
    • ChromeDriver is updated to current ChromeDriver v77.0 level.
    • Chrome is updated to the current Chrome Version 77.0 level. (as per ChromeDriver v77.0 release notes)
    • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
    • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
    • Take a System Reboot.
    • Execute your @Test as non-root user.
    0 讨论(0)
提交回复
热议问题