chrome開啟瀏覽器的python指令碼

weixin_33782386發表於2018-04-08

前提是將chromedriver拷貝到/usr/local/bin下了


class TestBaiDu(unittest.TestCase):

URL = Config().get('URL')

locator_kw = (By.ID, 'kw')

locator_su = (By.ID, 'su')

locator_result = (By.XPATH, '//div[contains(@class, "result")]/h3/a')

def setUp(self):

# self.driver = webdriver.Chrome(executable_path=DRIVER_PATH + '/chromedriver.exe')

        self.driver = webdriver.Chrome()

self.driver.get(self.URL)

def tearDown(self):

self.driver.quit()

def test_search_0(self):

self.driver.find_element(*self.locator_kw).send_keys('selenium')

self.driver.find_element(*self.locator_su).click()

time.sleep(2)

links =self.driver.find_elements(*self.locator_result)

for linkin links:

logger.info(link.text)

def test_search_1(self):

self.driver.find_element(*self.locator_kw).send_keys('Pythonselenium')

self.driver.find_element(*self.locator_su).click()

time.sleep(2)

links =self.driver.find_elements(*self.locator_result)

for linkin links:

logger.info(link.text)

if __name__ =='__main__':

unittest.main()

相關文章