selenium Python自動化 筆記 根據xpath找定位的響應屬性 修改鏈接並打開
阿新 • • 發佈:2017-10-11
print ram main import ttr body username div method
# coding=utf-8
import time
import unittest
from framework.browser_engine import BrowserEngine
from pageobjects.bird_homepage import HomePage
class BaiduSearch(unittest.TestCase):
@classmethod
def setUpClass(cls):
browse = BrowserEngine(cls)
cls.driver = browse.open_browser(cls)
@classmethod
def tearDownClass(cls):
cls.driver.quit()
def test_baidu_search(self):
homepage = HomePage(self.driver)
homepage.type_search(‘xx‘, ‘xxx‘)
# homepage.send_submit_btn()
self.driver.find_element_by_xpath("/html/body/div/div[2]/form/input[3]").click()
tempUrl = self.driver.find_element_by_link_text(
self.driver.find_element_by_xpath("/html/body/div[1]/div[2]/a[1]").text).get_attribute(‘href‘)
# print self.driver.find_element_by_xpath("/html/body/div[1]/div[2]/a[1]").text
# tempUrl=self.driver.current_url
L = tempUrl.split(‘u=‘)[0]
usernameOpen = 14852
openUrl = L + "u=" + str(usernameOpen)
self.driver.get(openUrl)
print tempUrl
time.sleep(35)
if __name__ == ‘__main__‘:
unittest.main()
selenium Python自動化 筆記 根據xpath找定位的響應屬性 修改鏈接並打開