0

I'm using selenium in python 3.8 and write a code to control chromedriver. The problem is there are too many tabs, almost 10 tabs, are opening when I call driver.get() They are really useless tabs and I only want to open one single tab with a browser. What's the problem with my code? Is there any solution?

Here is my code :

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--log-level=3")
chrome_options.add_experimental_option('excludeSwitches',['enable-logging'])
chrome_options.add_argument("'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'") 
driver = webdriver.Chrome("c:\chromedriver.exe", options=chrome_options)
driver.get('http://google.com')
Golden Lion
  • 3,840
  • 2
  • 26
  • 35
Rina K
  • 1
  • 1
  • 1
    Delete this line `chrome_options.add_argument("'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'"`. If you have to change the `user-agent`. Refer to this. https://stackoverflow.com/questions/49565042/way-to-change-google-chrome-user-agent-in-selenium – Abhishek Rai Apr 17 '21 at 14:48
  • It perfectly works! Thank you very much :D – Rina K Apr 17 '21 at 15:07
  • On checking again I see, that your quotes are wrong. It should be `chrome_options.add_argument('"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"')` – Abhishek Rai Apr 17 '21 at 15:12
  • 1
    Thank you very much Abhishek, that's the terrible mistake :$ – Rina K Apr 19 '21 at 20:49
  • Glad, could help. – Abhishek Rai Apr 19 '21 at 20:50

0 Answers0