SSLContext的Selenium NoClassDefFoundError

时间:2017-02-08 00:34:01

标签: java selenium selenium-webdriver selenium-chromedriver

我是硒测试的新手。在使用网站时,我收到一个错误:“main”java.lang.NoClassDefFoundError:org / apache / http / ssl / SSLContexts

你能帮我解决这个问题吗?

这是我的示例代码

Sub ClipboardToRows()
' Split multi-lined data into separate rows for the current selection
' Assumption is that Column A contains row headers
Dim currRange As Range, currCell As Range, pasteCell As Range
Dim rowHeader As String
Dim cellContent
Dim cellStr

Dim clipboard As MSForms.DataObject
Dim str1 As String
Set clipboard = New MSForms.DataObject

clipboard.GetFromClipboard
On Error GoTo clipEmpty
str1 = Trim(clipboard.GetText())

Application.CutCopyMode = False
Set currCell = Selection

rowHeader = Cells(currCell.Row, 1).Value
'Skip Column A
If (currCell.Column > 1) Then
    cellContent = Split(str1, Chr(10))
    For i = LBound(cellContent) To (UBound(cellContent))
        cellStr = Trim(cellContent(i))
        If Len(cellStr) > 0 Then
            Set pasteCell = currCell.Offset(i)
            'Set current cell with line 1
            If i = 0 Then
                currCell.Value = cellContent(i)
            Else
                'If next cell down is not empty or the row header is different
                If (Not IsEmpty(pasteCell.Value)) Or (Cells(pasteCell.Row, 1).Value <> rowHeader) Then
                    pasteCell.EntireRow.Insert
                    Cells(pasteCell.Row - 1, 1).Value = rowHeader
                End If
                currCell.Offset(i).Value = cellContent(i)

            End If
        End If
    Next
End If

clipEmpty:
    If Err <> 0 Then MsgBox "There was an issue with pasting. Please try again."

End Sub

控制台输出

public class TutorialsPointDownload {   
    public static void main(String[] args) {
            FirefoxProfile profile = new FirefoxProfile();
        profile.setAcceptUntrustedCertificates(true);
        profile.setAssumeUntrustedCertificateIssuer(false);
        WebDriver driver = new FirefoxDriver(profile);
        driver.get("https://www.tutorialspoint.com/software_testing_dictionary/acceptance_testing.htm");
        driver.findElement(By.xpath("/html/body/div[3]/div[1]/div/div[1]/aside/div[2]/div/ul[1]"));
        List<WebElement> we = driver.findElements(By.tagName("a"));
        System.out.println(we.size());
     }
}

依赖性添加:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ssl/SSLContexts
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.getSocketFactory(SSLConnectionSocketFactory.java:172)
    at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:71)
    at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:57)
    at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:60)
    at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.getDefaultHttpClientFactory(ApacheHttpClient.java:252)
    at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.<init>(ApacheHttpClient.java:229)
    at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:96)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:70)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:58)
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:87)
    at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:119)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:207)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:124)
    at TutorialsPointDownload.main(TutorialsPointDownload.java:57)
Caused by: java.lang.ClassNotFoundException: org.apache.http.ssl.SSLContexts
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 17 more

2 个答案:

答案 0 :(得分:2)

出现此问题的原因是SSLContext已重新定位到httpClient&gt; = 4.4中的另一个包。因此,我们需要将httpCore依赖项升级到4.4或任何新版本。

答案 1 :(得分:-2)

尝试创建所需的功能并设置

capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);