seleniumUI自动化测试文本框输入方法

from selenium import webdriver  
  
driver = webdriver.Chrome()  # 替换为你的浏览器驱动  
driver.get("http://www.example.com")  
  
# 假设你有一个输入框,其XPath是 '//input[@id="myInput"]'  
input_xpath = '//input[@id="myInput"]'  
text_to_paste = 'Hello, Selenium!'  
  
# 使用JavaScript设置输入框的值  
input_element = driver.find_element_by_xpath(input_xpath)  
driver.execute_script("arguments[0].value = arguments[1];", input_element, text_to_paste)  
  
# 如果你还需要触发其他事件,比如input或change事件,你可以这样:  
driver.execute_script("""  
    var evt = new Event('input', {bubbles: true});  
    arguments[0].dispatchEvent(evt);  
""", input_element)  
  
from selenium import webdriver  
from selenium.webdriver.common.action_chains import ActionChains  
from selenium.webdriver.common.keys import Keys  
  
driver = webdriver.Chrome()  # 替换为你的浏览器驱动  
driver.get("http://www.example.com")  
  
# 定位输入框  
input_element = driver.find_element_by_xpath('//input[@id="myInput"]')  

# 设置要“粘贴”的文本到剪贴板(这一步需要你使用其他方法,比如pyperclip库)  
# import pyperclip  
# pyperclip.copy('Hello, Selenium!')  
  
# 模拟粘贴操作(这里只是模拟按键,实际上并没有从剪贴板中复制粘贴)  
action_chains = ActionChains(driver)  
action_chains.move_to_element(input_element).click().send_keys(Keys.CONTROL, 'v').send_keys(Keys.CONTROL).perform()  
  
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容