【问题标题】:Selenium - element not being found (python)Selenium - 找不到元素(python)
【发布时间】:2019-06-20 18:28:05
【问题描述】:

尝试使用 selenium 将键发送到文本框,但即使在使用显式等待之后,它似乎也无法找到元素。

注意:我刚开始学习 python,所以我可能在这里遗漏了一些重要的东西。

Selenium 能够在此页面之前找到站点上的所有元素(不确定它是否是新页面,因为 URL 不会更改,但页面中的模块会更改)。我已经尝试了所有可能的元素定位方法(XPATH、ID、CLASS_NAME 等),但似乎找不到这个文本框元素。我尝试使用它来定位页面上的其他元素,但它似乎也无法找到它们。

#My code:
#imported expected_conditions as EC
wait = WebDriverWait(browser, 15)
wait.until(EC.presence_of_element_located((By.XPATH, '// 
[@id="payment_amount_value"]')))

#Element:
  <input type="text" class="input-mini text_input span10" 
   id="payment_amount_value" aria-describedby="payment-amount-error- 
   message" data-submit="paymentAmount">

    #Error Message:
    Traceback (most recent call last):
      File "<string>", line 100, in <module>
      File "/anaconda3/lib/python3.6/site- 
   packages/selenium/webdriver/support/wait.py", line 80, in until
        raise TimeoutException(message, screen, stacktrace)
    selenium.common.exceptions.TimeoutException: Message: 

【问题讨论】:

标签: python selenium google-chrome webdriver element


【解决方案1】:

感谢您的帮助,莫舍!原来该元素在 iframe 中,我不得不使用以下命令切换到它:

iframe = wait.until(EC.presence_of_element_located((By.XPATH,'//*[@id="billing-app-container"]/iframe')))
browser.switch_to.frame(iframe)

【讨论】:

  • 你应该除了你自己的答案...你可以点击# of votes下的V
【解决方案2】:

更改您的 xpath:

wait = WebDriverWait(browser, 15)
the_input = wait.until(EC.presence_of_element_located((By.XPATH, '//input[@id="payment_amount_value"]')))
the_input.send_keys("Bla-bla")

希望对您有所帮助!

【讨论】:

    猜你喜欢
    • 2021-12-17
    • 2018-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多