from selenium import webdriver
from selenium.webdriver import ActionChains
from time import sleep
from selenium.webdriver.common.keys import Keys
class TestCase(object):
def __init__(self):
self.driver = webdriver.Chrome()
self.driver.maximize_window()
#self.driver.get("http://sahitest.com/demo/clicks.htm")
def test_mourse(self):
db_btn = self.driver.find_element_by_xpath('/html/body/form/input[2]')
ActionChains(self.driver).double_click(db_btn).perform()
# sleep(1)
d_btn = self.driver.find_element_by_xpath('/html/body/form/input[3]')
ActionChains(self.driver).click(d_btn).perform()
r_btn = self.driver.find_element_by_xpath('/html/body/form/input[4]')
# sleep(1)
ActionChains(self.driver).context_click(r_btn).perform()
# sleep(1)
text= self.driver.find_element_by_xpath('/html/body/form/textarea').get_attribute('value')
print(text)
print(text.split(']',num=str.count(text)))
# 鼠标悬停
def hover(self, by, value):
element = self.findElement(by, value)
ActionChains(self.driver).move_to_element(element).perform()
def test_key(self):
self.driver.get("https://wwwpre.125339.com.cn")
sleep(1)
# self.driver.find_element_by_xpath('//*[@id="head"]/ul/li[6]/a').click()
self.driver.find_element_by_link_text('关于我们').click()
sleep(1)
# 找到意见反馈
self.driver.find_element_by_xpath('/html/body/div/div[3]/div/div[1]/div[5]/div/div[2]/div').click()
# 意见反馈-文本输入框
yjfk = self.driver.find_element_by_xpath('//*[@id="fb-desc"]')
# 输入内容
yjfk.send_keys('中国移动云视讯')
# ctrl+a
yjfk.send_keys(Keys.CONTROL,'a')
sleep(2)
# ctrl+x
yjfk.send_keys(Keys.CONTROL,'x')
sleep(2)
# ctrl+v
yjfk.send_keys(Keys.CONTROL,'v')
sleep(5)
if __name__ == '__main__':
case = TestCase()
# case.test_mourse()
case.test_key()
case.driver.quit()