在Ajax方式产生浮动框,单击选择包含关键字 如下:
from selenium import webdriver
import traceback
import unittest
import time
class TestDemo(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
def test_Ajax(self):
url = 'http://www.baidu.com'
self.driver.get(url)
try:
box = self.driver.find_element_by_id('kw')
box.send_keys(u'光荣')
time.sleep(3)
# 查询使命悬浮选项
# option=self.driver.find_element_by_xpath('//*[@class="suglist"]/li[6]')#xpath定位某一项
option = self.driver.find_element_by_xpath('//ul/li[contains(.,"使命")]') # xpath模糊定位
option.click()
time.sleep(3)
except NotADirectoryError as e:
print(traceback.print_exc(), e)
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()