Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

More specifically, is it safe to perform multiple operations on a single WebDriver/WebElement simultaneously? i.e. something like this

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();

I've tried this myself without problems when interacting locally, but run into intermittent problems when doing the same thing against a remote selenium grid.

I'm not sure if the problems I'm experiencing are coming from Selenium itself, or if Selenium is fine and it's a limitation of the hosted grid provider I'm using. Is selenium thread safe for scraping with Python? mentions that selenium might not be thread safe, but I couldn't find any confirmation.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
225 views
Welcome To Ask or Share your Answers For Others

1 Answer

This question is answered 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. "


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...