Now able to open multiple windows: selenium.common.exceptions.WebDriverException: invalid session id

0 votes

I am trying to open a window, do some scraping and close it. I am trying to do this in a loop. This is the code:

from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
import time

chromedriver = "F:\omkar\Download\chromedriver"
driver = webdriver.Chrome(chromedriver)

for i in range(0,3):
    url="https://www.edureka.co/community/users?start=" + str(i*200)
    driver.get(url)
    time.sleep(3)
    driver.close()

It opens the first window with no problem but the second window doesn’t open. I get this error

selenium.common.exceptions.WebDriverException: Message: invalid session id
Apr 5, 2019 in Python by Raj
5,300 views

1 answer to this question.

0 votes

You have initialized driver only once and are trying to use the same driver to open and close windows multiple time. Maybe that’s the reason for this reason.

Try this:

for i in range(0,3):
    chromedriver = "F:\omkar\Download\chromedriver"
    driver = webdriver.Chrome(chromedriver)
    url="https://www.edureka.co/community/users?start=" + str(i*200)
    driver.get(url)
    time.sleep(3)
    driver.close()
answered Apr 5, 2019 by James

Related Questions In Python

0 votes
1 answer
0 votes
0 answers
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
3,827 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,807 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,772 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
3,149 views
0 votes
1 answer

How to create empty pandas dataframe only with column names?

You can do it like this: df=pd.DataFrame(columns=["Name","Old","Ne ...READ MORE

answered Apr 5, 2019 in Python by Hari
5,301 views