Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable javascript in selenium webdriver Chrome using python

I am trying to open https://www.guidestar.org/ using selenium webdriver but it is able to detect I am a bot. The email I received says that javascript was not enabled so they were blocking my IP address. Can anyone suggest a code to enable javascripts

user_agent = 'Chrome/73.0.3683.86'
username = os.getenv("USERNAME")
userProfile = "C:\\Users\\" + username + "\\AppData\\Local\\Google\\Chrome\\User Data\\Default"
options = webdriver.ChromeOptions()
options.add_argument(f'user-agent={user_agent}')
options.add_argument("user-data-dir={}".format(userProfile))
driver = webdriver.Chrome(chrome_options=options)
driver.get("http://www.guidestar.org")

I expected the website not to detect that I am a robot

like image 795
akashav1 Avatar asked Apr 02 '19 17:04

akashav1


People also ask

Can Selenium execute JavaScript?

Selenium is capable of executing JavaScript commands with the execute_script method. Few actions like web scrolling cannot be done by Selenium directly. For this, we shall use the JavaScript Executor. We shall take the help of the JavaScript command window.

Where do we use JavaScript in Selenium?

To simplify the usage of JavascriptExecutor in Selenium, think of it as a medium that enables the WebDriver to interact with HTML elements within the browser. JavaScript is a programming language that interacts with HTML in a browser, and to use this function in Selenium, JavascriptExecutor is required.


1 Answers

answers provided here won't work. instead, use

    options.add_argument("--enable-javascript")
like image 176
Alex Manuele Avatar answered Nov 14 '22 21:11

Alex Manuele