Selenium's WebDriver.execute_script() returns 'None'
selenium, selenium-webdriver
Solution
Return the value:
content = browser.execute_script("return document.getElementsByClassName('content');");
Problem
My program is having trouble getting an existing class from a webpage using Selenium. It seems that my WebDriver.execute_script function is not working. ``` import urllib from selenium import webdriver #Path to the chromedriver is definitely working fine. path_to_chromedriver = 'C:\Users\Ben\Desktop\Coding\FreeFoodFinder\chromedriver.exe' browser = webdriver.Chrome(executable_path = path_to_chromedriver) url = 'http://www.maidservicetexas.com/' browser.implicitly_wait(30) browser.get(url) content = browser.execute_script("document.getElementsByClassName('content')"); #Just printing the first character of the returned content's toString for now. Don't want the whole thing yet. #Only ever prints 'N', the first letter of 'None'...so obviously it isn't finding the jsgenerated content even after waiting. print content ``` My program returns 'None,' which tells me that the javascript function is not returning a value/being executed. Chrome's web dev tools tell me that 'content' is certainly a valid class name. The webpage isn't even dynamically generated (my eventual goal is to scrape dynamic content, which is why I make my WebDriver wait for 30 seconds before running the script.)