0

how do I enable javascript in selenium using python? I tried several methods but mine isnt working. Does anyone know how could i fix this issue? Thanks

My code

from selenium import webdriver
import urllib
import urllib.request
import string
from bs4 import BeautifulSoup
import mysql.connector
import time

chrome_path = r"C:\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.add_argument("--enable-javascript")

Error i got

Exception has occurred: AttributeError
'WebDriver' object has no attribute 'add_argument'
  File "C:\Users\bustillo-ronald\Desktop\python-basics\Scrape\propertyguru.py", line 11, in <module>
    driver.add_argument("--enable-javascript")

1 Answer 1

1

You need to create an instance of a ChromeOptions object first and add_argument to that. Then pass the options object as an argument to the Chrome webdriver.

something like this

options = webdriver.ChromeOptions()
options.add_argument("--enable-javascript")

# Now back to your code
driver = webdriver.Chrome(chrome_path, options=options)

...
Sign up to request clarification or add additional context in comments.

7 Comments

i already did like this sir from selenium.webdriver.chrome.options import Options opt = webdriver.ChromeOptions() opt.add_argument("--enable-javascript") chrome_path = r"C:\chromedriver.exe" driver = webdriver.Chrome(chrome_path,chrome_options=opt) But the site that i want to scrape doesnt let me to access because javascript is disabled
the site says cant identify my browser. its because javascript or cookies are disabled. how to prevent this sir?
How is the site indicating this to you?
when i run my code then the browser says cant identify my browser because of disabled javascript
What happens if you run this: driver.get("https://www.whatismybrowser.com/detect/is-javascript-enabled") assert(driver.find_element_by_id("detected_value").text=="Yes")
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.