主题
以下是一个简单的Python示例,演示如何使用Selenium打开Google首页并搜索"Hello, World!":
python
from selenium import webdriver
# 创建Firefox浏览器实例
driver = webdriver.Firefox()
# 让浏览器打开Google首页
driver.get("http://www.google.com")
# 找到搜索框元素
search_box = driver.find_element_by_name("q")
# 在搜索框中输入文字
search_box.send_keys("Hello, World!")
# 提交搜索
search_box.submit()
# 关闭浏览器
driver.quit()
请注意,实际使用时需要根据你的环境和需求进行适当的调整。