简体   繁体   中英

Why is my Selenium selector pulling a dict? (Django/Python 3.8)

I've just updated selenium in my django app on PythonAnywhere. This is my code:

from selenium import webdriver

def Synonym():
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("--headless")
    chrome_options.add_argument("--disable-gpu")
    browser = webdriver.Chrome(options=chrome_options)
    browser.get("https://www.synonym.com/synonyms/test")
    test = browser.find_element_by_class_name("logo").text
    browser.quit()

    return test

But it gives me an error:

AttributeError: 'dict' object has no attribute 'text'

When I grab it without the .text this is what it gives me:

{'ELEMENT': '0.3567871003333163-1'} 

I'm using a paid account and should be able to access any site. Sidenote: is there a way to stop selenium from making /tmp/ files and folders?

Thanks!

The fix for me on PythonAnywhere was to update the system image: https://help.pythonanywhere.com/pages/ChangingSystemImage

Answer courtesy of caseneuve!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM