如何在iframe与Selenium(Python)中的blogspot上发表评论

提问

我想在一个含有硒色的河流和Python的博客上评论。我尝试了许多方法,但失败了。我如何运行下面的代码? 我在这条线上犯了一个错误: 请帮忙评论一下硒。 编辑… 测试网址: 错误stacktrace: 将一个字符序列发送到注释体字段,因为元素在一个< iframe >中,所以必须: 引导web驱动程序等待所需的帧,并切换到它。 引导web驱动程序等待所需的元素可点击。 您可以使用以下定位器策略: 注意:您必须添加以下导入:

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()

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

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

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]
回答

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")

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

▼版权说明

相关文章也很精彩
推荐内容
更多标签
相关热门
全站排行
随便看看

错说cuoshuo.com——程序员的报错记录

部分内容根据CC版权协议转载,如果您希望取消转载请发送邮件到cuoshuo8@163.com

辽ICP备19011660号-5