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]
To send a character sequence to the commentBody field as the elements are within an <iframe>
so you have to:
Induce WebDriverWait for the desired frame to be available and switch to it.
Induce WebDriverWait for the desired element to be clickable.
You can use the following locator strategies:
driver.get('https://clearing.apcs.at/emwebapcsem/startApp.do')
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name='comment-editor']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "commentBody"))).send_keys("Akif")
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC