javascriptpythonseleniumselenium-webdriver

Issue with AttributeError: 'WebDriver' object has no attribute 'manage'


My code:

commentr = driver.find_element_by_id("simplebox-placeholder")
commentr.click()

driver.execute_script("document.getElementById('simplebox- 
placeholder').value = 'your comment text here';")
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
commentr.send_keys("HELO")

My error:

Traceback (most recent call last): File "C:\Users\weqwwg\Desktop\python\Game.py", line 77, in driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); AttributeError: 'WebDriver' object has no attribute 'manage'

I'm trying to send a key to the comment box on youtube. I removed some code, I am currently running this code.

commentr = driver.find_element_by_id("simplebox-placeholder")
commentr.click()
driver.implicitly_wait(10)
commentr.send_keys("HELO")

This is the error I'm getting:

Traceback (most recent call last):
  File "C:\Users\Brandsdo\Desktop\python\Game.py", line 76, in <module>
    commentr.send_keys("HELO")
  File "C:\Users\Braasdasndo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys
    'value': keys_to_typing(value)})
  File "C:\Users\Brsadasdando\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\Braasdasndo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Braasdando\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=73.0.3683.103)
  (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Windows NT 10.0.17763 x86_64)

UPDATED PART OF CODE

driver.find_element_by_id("simplebox-placeholder").click()

commentr = WebDriverWait(driver,10).until(EC.element_to_be_clickable( (By.ID, 'contenteditable-textarea') ))

commentr.click().send_keys("HELO")
driver.find_element_by_id("submit-button").click()

THIS IS THE ERROR

Traceback (most recent call last): File "C:\Users\Desktop\python\Game.py", line 74, in commentr.click().send_keys("HELO") AttributeError: 'NoneType' object has no attribute 'send_keys'


Solution

  • This is answer to an original question:

    To fix your immediate problem, use

    driver.implicitly_wait(10)
    

    Manual is there

    However you are probably going in a wrong direction altogether. Instead, try to use the WebDriverWait module.

    from selenium.webdriver.support.ui import WebDriverWait
    

    For example:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    #...
    
    footer = WebDriverWait(driver, 10).until(EC.visibility_of_element_located(
       (By.CSS_SELECTOR, ".b-footer__divider"))
    )
    

    Update for the updated part of question:

    I'm trying to send a key to the comment box on youtube. I removed some code, I am currently running this code.

    As I suspected, you don't need the implicitly_wait function at all there.

    In a simple approach, you should locate this element and send keystrokes into it:

    commentr = driver.find_element_by_id("contenteditable-textarea")
    commentr.click()
    commentr.send_keys("HELO")
    

    But when you are clicked to simplebox-placeholder, it could take some time for page to perform the necessary actions and make the contenteditable-textarea visible and clickable. The approach below will allow you to avoid exception if an element is not ready yet:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    commentr = WebDriverWait(driver,10).until(EC.element_to_be_clickable( (By.ID, 'contenteditable-textarea') ))
    commentr.click()
    commentr.send_keys("HELO")
    

    driver.find_element_by_id("submit-button").click()
    

    Overall, your code could look like:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    driver.find_element_by_id("simplebox-placeholder").click()
    
    commentr = WebDriverWait(driver,10).until(EC.element_to_be_clickable( (By.ID, 'contenteditable-textarea') ))
    
    commentr.click()
    commentr.send_keys("HELO")
    driver.find_element_by_id("submit-button").click()