1
0
Fork 0
EnglishPal/app/test/test_bug545_HuangHuiLing.py

75 lines
2.4 KiB
Python

import random
import string
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from helper import signup
def has_punctuation(s):
return any(c in string.punctuation for c in s)
def select(driver):
text_element = driver.find_element(By.ID, 'article')
# 创建ActionChains对象
actions = ActionChains(driver)
# 模拟鼠标移动到文本元素上
actions.move_to_element(text_element)
# 模拟鼠标按下并拖动以选择文本
# 假设我们想要选择从第10个字符开始的5个字符
actions.click()
actions.perform()
time.sleep(5)
# 找到包含要选择文字的元素
text_element = driver.find_element(By.ID, 'article_title')
# 创建ActionChains对象
actions = ActionChains(driver)
# 模拟鼠标移动到文本元素上
actions.move_to_element(text_element)
# 模拟鼠标按下并拖动以选择文本
# 假设我们想要选择从第10个字符开始的5个字符
actions.double_click()
actions.perform()
#actions.move_by_offset(100, 0)
#actions.move_by_offset(10, 0)
actions.release() # 释放鼠标按钮
def test_selected_second_word(driver, URL):
try:
username, password = signup(URL, driver)
# 找到包含要选择文字的元素
text_element = driver.find_element(By.ID, 'article_title')
# 创建ActionChains对象
actions = ActionChains(driver)
# 模拟鼠标移动到文本元素上
actions.move_to_element(text_element)
# 模拟鼠标按下并拖动以选择文本
# 假设我们想要选择从第10个字符开始的5个字符
actions.double_click()
actions.perform()
#actions.move_by_offset(10, 0)
# 获取选中的文本
selected_words = driver.find_element(By.ID, 'selected-words').get_attribute('value')
assert selected_words != "","选中单词被放置框中"
#再次选取
select(driver)
time.sleep(6)
selected_second_words = driver.find_element(By.ID, 'selected-words').get_attribute('value')
assert selected_second_words.strip() == "", "选中的单词被删除"
finally:
driver.quit()