我想使用 Selenium IDE 在 Chrome 中完成一些簡單的任務,然后將代碼導出到 python 并在那里執(zhí)行。但是,當我在 python 中執(zhí)行導出的代碼時,什么也沒有發(fā)生。# Generated by Selenium IDEimport pytestimport timeimport jsonfrom selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium.webdriver.support import expected_conditionsfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesclass TestIDETest(): def setup_method(self, method): self.driver = webdriver.Chrome('C:/Users/Jakob/Documents/Python-Selenium/chromedriver.exe') self.vars = {} def teardown_method(self, method): self.driver.quit() def test_iDETest(self): self.driver.get("https://www.google.de/") self.driver.set_window_size(1050, 660) self.driver.find_element(By.NAME, "q").send_keys("wikipedia") self.driver.find_element(By.NAME, "q").send_keys(Keys.ENTER) self.driver.find_element(By.CSS_SELECTOR, ".rc:nth-child(3) .LC20lb").click() self.driver.find_element(By.ID, "txtSearch").click() self.driver.find_element(By.ID, "txtSearch").send_keys("delta") self.driver.find_element(By.ID, "txtSearch").send_keys(Keys.ENTER) self.driver.find_element(By.LINK_TEXT, "English").click() element = self.driver.find_element(By.CSS_SELECTOR, ".mw-wiki-logo") actions = ActionChains(self.driver) actions.move_to_element(element).perform() element = self.driver.find_element(By.CSS_SELECTOR, "body") actions = ActionChains(self.driver) actions.move_to_element(element, 0, 0).perform() element = self.driver.find_element(By.CSS_SELECTOR, "#ca-talk > a") actions = ActionChains(self.driver) actions.move_to_element(element).perform() self.driver.close()當我刪除類和方法并只執(zhí)行它工作的“原始”代碼時。所以我不確定如何使用這些方法。提前致謝。
1 回答

斯蒂芬大帝
TA貢獻1827條經(jīng)驗 獲得超8個贊
如果你想讓它按原樣運行,你需要實例化類并啟動里面的函數(shù)。在腳本末尾添加:
testClass = TestIDETest()
testClass.setup_method("")
testClass.test_iDETest()
testClass.teardown_method("")
我之前沒有從 IDE 中導出過,所以我無法評論它想要的“方法”變量的用途(而且它似乎沒有對它做任何事情)——但它是空白的。
添加回答
舉報
0/150
提交
取消