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) ... 
    7
    • 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
      – draw134
      CommentedNov 25, 2019 at 3:15
    • the site says cant identify my browser. its because javascript or cookies are disabled. how to prevent this sir?
      – draw134
      CommentedNov 25, 2019 at 3:27
    • How is the site indicating this to you?
      – MSlimmer
      CommentedNov 25, 2019 at 4:47
    • when i run my code then the browser says cant identify my browser because of disabled javascript
      – draw134
      CommentedNov 25, 2019 at 5:28
    • 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")
      – MSlimmer
      CommentedNov 25, 2019 at 7:00

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.