python - 用于 selenium 的 firefox IDE 是否使用 selenium lib 导出到常规 python 代码?

标签 python selenium

python selenium lib 页面有以下示例:

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.common.keys import Keys
from time

browser = webdriver.Firefox() # Get local session of firefox
browser.get("http://www.yahoo.com") # Load page
assert browser.title == "Yahoo!"
elem = browser.find_element_by_name("p") # Find the query box
elem.send_keys("selenium" + Keys.RETURN)
time.sleep(0.2) # Let the page load, will be added to the API
try:
    browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]")
except NoSuchElementException:
    assert 0, "can't find seleniumhq"
browser.close()

但是当我从 firefox selenium IDE 导出保存的 session 时,python 代码看起来有很大不同:

from selenium import selenium
import unittest, time, re

class create_order(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium("localhost", 4444, "*chrome", "http://localhost/")
        self.selenium.start()

    def test_create_order(self):
        sel = self.selenium
        sel.open("/User/LogOn")
        sel.type("UserName", "testuser")
        sel.type("Password", "123")
        sel.click("//input[@value='login']")
        sel.wait_for_page_to_load("30000")
        sel.click("link=Settings")
        sel.wait_for_page_to_load("30000")
        sel.click("//input[@value='Some Link']")
        sel.wait_for_page_to_load("30000")      
        sel.click("link=Save>")
        sel.wait_for_page_to_load("30000")

    def tearDown(self):
        self.selenium.stop()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

是否使用了不同的 API?

最佳答案

第一个代码段使用较新的 WebDriver API。

第二个片段使用原始的 Selenium 1 API。

http://seleniumhq.org/docs/03_webdriver.html

关于python - 用于 selenium 的 firefox IDE 是否使用 selenium lib 导出到常规 python 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5517822/

相关文章:

python - 用 pandas 替换字符串

javascript - 以编程方式检索页面上的 javascript 错误计数

testing - 如何将 Selenium RC 用于 Selenium IDE 测试用例依赖?

selenium - Selenium Grid总是执行我的测试的多余实例

ruby-on-rails - Rspec 不执行 AJAX 调用

python - 启用从 jupyterhub 笔记本服务器下载多文件吗?

python - 将所有 pcap 文件转换为包含所需列的 csv python

python - 如何在 ModelForm 的自定义表单字段中预填充值

python - 如何将 optgroups 添加到 django ModelMultipleChoiceField?

python - 使用 Selenium 保存在浏览器中打开的 pdf