我想使用 Selenium IDE 在 Chrome 中完成一些簡(jiǎn)單的任務(wù),然后將代碼導(dǎo)出到 python 并在那里執(zhí)行。但是,當(dāng)我在 python 中執(zhí)行導(dǎo)出的代碼時(shí),什么也沒(méi)有發(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()當(dāng)我刪除類和方法并只執(zhí)行它工作的“原始”代碼時(shí)。所以我不確定如何使用這些方法。提前致謝。
1 回答

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