【问题标题】:Selenium Automation "Unable to locate element" error on the web UI of qbittorrent applicationqbittorrent 应用程序的 Web UI 上的 Selenium 自动化“无法定位元素”错误
【发布时间】:2021-08-27 04:08:54
【问题描述】:

我正在尝试使用 BitTorrent Web UI 自动下载带有磁力链接的电影。我可以单击“添加 torrent 链接”按钮,弹出窗口确实出现,但之后,代码失败,因为它无法找到需要添加 torrent 链接的元素。当我尝试输入文件位置时,也会出现同样的问题。我尝试了time.sleep,但没有运气。

我的代码 sn-p:

def torrent(path, n):
    #link to web UI
    driver.get("http://127.0.0.1:8080/")
    #default login credentials
    username = driver.find_element_by_xpath("//*[@id='username']")
    username.send_keys("admin")
    password = driver.find_element_by_xpath("//*[@id='password']")
    password.send_keys("adminadmin")
    time.sleep(2)
    driver.find_element_by_xpath("//*[@id='login']").click()
    time.sleep(2)
    #the elements I am trying to find
    driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/a[1]").click()
    time.sleep(5)
    location = driver.find_element_by_xpath("/html/body/form/div/fieldset/table/tbody/tr[2]/td[2]")
    location.send_keys(path)
    input = driver.find_element_by_xpath("/html/body/form/div/textarea")
    i = 0
    while i <= n-1:
        input.send_keys(list_torrent[i])

如果您需要任何其他信息,请告诉我。我已经尝试使用 BitTorrent API,但没有运气。 HTML 页面有一个隐藏的溢出,但这应该不是问题,因为我单击了应该使我的代码可见的元素。 提前致谢。

【问题讨论】:

    标签: python html python-3.x selenium


    【解决方案1】:

    看起来它在 iframe 中。

    像这样切换到iframe

    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH," Ifrmae xpath here"))) 
    

    然后在这里做其他的事情:

    使用 iframe 完成后,将其切换回 default_content 像这样:

    driver.switch_to.default_content()
    

    【讨论】:

      猜你喜欢
      • 2015-09-19
      • 2020-12-29
      • 2020-06-21
      • 1970-01-01
      • 2021-11-19
      • 1970-01-01
      • 1970-01-01
      • 2018-02-14
      • 2019-01-25
      相关资源
      最近更新 更多