【问题标题】:Convert Selenium IDE Syntax to Python Webdriver将 Selenium IDE 语法转换为 Python Webdriver
【发布时间】:2015-11-30 17:14:04
【问题描述】:

在 Selenium IDE 中,它告诉我使用命令

selectWindow

目标是:

name={"id":"a52b0dc5-b1f5-2020-01db-139f01c0204a","containerVersion":"7-GA","webContextPath":"/345","preferenceLocation":"https:/url/345/prefs","relayUrl":"https:/url/o345/is/eas/rpc_relay.uncompressed.html","lang":"en_US","currentTheme":{"themeName":"a_default","themeContrast":"standard","themeFontSize":12},"345":true,"layout":"desktop","url":"/brvt","guid":"260f0022-66de-a78b-3ce8-8de63a3bdbec","version":1,"locked":false}

如何在 python 中使用driver.switch_to_window 进行转换?

我试过了:

driver.switch_to_window(driver.find_element_by_name("{"id":"a52b0dc5-b1f5-2020-01db-139f01c0204a","containerVersion":"7-GA","webContextPath":"/345","preferenceLocation":"https:/url/345/prefs","relayUrl":"https:/url/o345/is/eas/rpc_relay.uncompressed.html","lang":"en_US","currentTheme":{"themeName":"a_default","themeContrast":"standard","themeFontSize":12},"345":true,"layout":"desktop","url":"/brvt","guid":"260f0022-66de-a78b-3ce8-8de63a3bdbec","version":1,"locked":false}"))

建议?

【问题讨论】:

  • 似乎IDE和WebDriver有不同的方式来识别对象...如果您想确定如何选择窗口:在所需窗口上单击右键,然后单击“探索元素的代码" 或类似的东西(取决于浏览器)来获取 html 源代码。复制它并使用这部分代码更新您的问题,然后我可以告诉您在 Python 脚本中使用的正确选择器
  • 在窗口之间切换的非常简单的方法(理想情况下是 2 个)gist.github.com/ab9-er/08c3ce7d2d5cdfa94bc7。告诉我这是否适合你。
  • 它对你有用吗?
  • 请采纳答案。

标签: python selenium iframe selenium-webdriver


【解决方案1】:

在窗口之间切换的一种非常简单的方法(最好是 2 个)gist.github.com/ab9-er/08c3ce7d2d5cdfa94bc7

def change_window(browser):
    """
    Simple window switcher without the need of playing with ids.
    @param browser: Current browser instance
    """
    curr = browser.current_window_handle
    all_handles = browser.window_handles
    for handle in list(set([curr]) - set(all_handles)):
        return browser.switch_to_window(handle)

【讨论】:

    猜你喜欢
    • 2016-02-23
    • 2016-05-17
    • 2020-05-24
    • 1970-01-01
    • 2017-03-27
    • 2017-06-26
    • 1970-01-01
    • 2021-05-03
    • 1970-01-01
    相关资源
    最近更新 更多