【问题标题】:selenium error after entering the header file web driver进入头文件web驱动后selenium报错
【发布时间】:2018-02-07 09:44:28
【问题描述】:

[头文件[][1]1seelnium webdriver 错误 线程“主”java.lang.NoClassDefFoundError 中的异常:org/openqa/selenium/support/ui/Select(错误名称:org/openqa/selenium/support/ui/select)

尝试过的代码:-

Select select = new Select(driver.findElement(By.cssSelector("body > app-root > app-patient-index > app-patient-profile > div.s_detail_doc_wrapper > div.s_patient_detail_tab > div > tabset > div > tab.active.tab-pane > form > div > div.s_patient_profile_form > div > div.col-md-9 > ul > li:nth-child(2) > div > div.col-md-9 > div > div.col-sm-5.pl0 > select"))); 

select.deselectAll(); 
select.selectByVisibleText("Married");

enter image description here 在此处输入图片说明

【问题讨论】:

  • 选择 select = new Select(driver.findElement(By.cssSelector("body > app-root > app-patient-index > app-patient-profile > div.s_detail_doc_wrapper > div.s_patient_detail_tab > div > tabset > div > tab.active.tab-pane > form > div > div.s_patient_profile_form > div > div.col-md-9 > ul > li:nth-child(2) > div > div.col-md- 9 > div > div.col-sm-5.pl0 > 选择"))); select.deselectAll(); select.selectByVisibleText("已婚");]
  • 您使用的是哪个版本的 Selenium?
  • 你在哪一行得到错误?
  • 使用版本 3

标签: selenium testing selenium-webdriver


【解决方案1】:

请使用以下代码从下拉列表中选择值。

注意:如果下拉菜单是选择类型。

要使用的导入是。

import org.openqa.selenium.support.ui.Select;


System.setProperty("webdriver.chrome.driver","Drivers/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com/");
Thread.sleep(3000);
Select dayDropDown = new Select(driver.findElement(By.xpath("//select[@name='birthday_day']")));
dayDropDown.selectByVisibleText("5");

【讨论】:

  • 线程“主”java.lang.NoClassDefFoundError 中的异常:org/openqa/selenium/support/ui/Select(错误名称:org/openqa/selenium/support/ui/select)在 java。 lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net。 URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source)
  • 在 java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang。 ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at Safety.safety_signin.main(safety_signin.java:60)
  • @Sayooj,我只复制了你的代码,但我没有收到java.lang.NoClassDefFoundError
  • 使用 selenium-server-standalone-3.8.1 ,希望它能为你解决问题
  • 使用 selenium 3.8.1 后是否仍然出现错误,能否发布完整代码?
【解决方案2】:

在您丢失的 elenium-support jar 中发现缺少 Select 类。

您可以直接从以下位置下载 jar,例如 2.0a7 版本: http://central.maven.org/maven2/org/seleniumhq/selenium/selenium-support/2.0a7/selenium-support-2.0a7.jar

或者添加maven依赖

  <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-support -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-support</artifactId>
        <version>2.0a7</version>
    </dependency>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-28
    • 1970-01-01
    • 1970-01-01
    • 2016-10-08
    • 1970-01-01
    • 1970-01-01
    • 2017-08-15
    相关资源
    最近更新 更多