Selenium WebDriver 线程安全吗?

Is Selenium WebDriver thread safe?

更具体地说,同时对单个 WebDriver/WebElement 执行多个操作是否安全?即像这样

WebDriver driver; //driver initialized somehow
final WebElement elem = driver.findElement(By.cssSelector("#elementID"));

//simplified for example, but in real code I'd be storing the results of these calls
new Thread() {
    @Override
    public void run() {
        elem.isDisplayed();
    }
}.run();
new Thread() {
    @Override
    public void run() {
        elem.isEnabled();
    }
}.run();

我自己在本地交互时没有遇到任何问题,但在对远程 selenium 网格执行相同操作时 运行 遇到间歇性问题。

我不确定我遇到的问题是否来自 Selenium 本身,或者 Selenium 是否正常并且它是我正在使用的托管网格提供商的限制。 Is selenium thread safe for scraping with Python? 提到 selenium 可能不是线程安全的,但我找不到任何确认。

此问题已回答here

"WebDriver is not thread-safe. Having said that, if you can serialize access to the underlying driver instance, you can share a reference in more than one thread. This is not advisable. You /can/ on the other hand instantiate one WebDriver instance for each thread. "