pythonseleniumiframewebdriverwaitexpected-condition

How to comment on blogspot within an iframe with Selenium(Python)


I would like to comment on a blogspot with selenium, chromedriver and python. I tried many methods but failed. How can I run my code below?

driver.get(url)
iframe = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.NAME, 'comment-editor')))
driver.switch_to.frame(iframe)

element=WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.NAME, 'commentBody')))

actionChains = ActionChains(driver)
actionChains.move_to_element(element).click().perform()
actionChains.move_to_element(element).send_keys(text).perform()

I'm getting an error on this line:

element=WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.NAME, 'commentBody')))

Please help to comment with selenium.

Edit.. test url : https://lf2011b8308.blogspot.com/2011/12/macronutrients-carbohydrates-proteins.html

Error stacktrace:

Traceback (most recent call last):
  File "C:/Users/Hotto/PycharmProjects/blogspot/chromes.py", line 51, in <module>
    element=WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.NAME, 'commentBody')))
  File "C:\Users\Hotto\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\support\wait.py", line 89, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
Stacktrace:
Backtrace:
    Ordinal0 [0x00405FD3+2187219]
    Ordinal0 [0x0039E6D1+1763025]
    Ordinal0 [0x002B3E78+802424]
    Ordinal0 [0x002E1C10+990224]
    Ordinal0 [0x002E1EAB+990891]
    Ordinal0 [0x0030EC92+1174674]
    Ordinal0 [0x002FCBD4+1100756]
    Ordinal0 [0x0030CFC2+1167298]
    Ordinal0 [0x002FC9A6+1100198]
    Ordinal0 [0x002D6F80+946048]
    Ordinal0 [0x002D7E76+949878]
    GetHandleVerifier [0x006A90C2+2721218]
    GetHandleVerifier [0x0069AAF0+2662384]
    GetHandleVerifier [0x0049137A+526458]
    GetHandleVerifier [0x00490416+522518]
    Ordinal0 [0x003A4EAB+1789611]
    Ordinal0 [0x003A97A8+1808296]
    Ordinal0 [0x003A9895+1808533]
    Ordinal0 [0x003B26C1+1844929]
    BaseThreadInitThunk [0x7697343D+18]
    RtlInitializeExceptionChain [0x77729812+99]
    RtlInitializeExceptionChain [0x777297E5+54]

Solution

  • To send a character sequence to the commentBody field as the elements are within an <iframe> so you have to: