针对https://accounts.gbihealth.com.cn/?returnUrl=https://source.gbihealth.com.cn?redirect=%2Fproduct%2Fdetail%3Fid%3D2008491 网站写一个自动化登录测试用例
时间: 2023-12-30 15:05:06 浏览: 34
好的,以下是一个使用Python和Selenium库编写的自动化登录测试用例,针对 https://accounts.gbihealth.com.cn/?returnUrl=https://source.gbihealth.com.cn?redirect=%2Fproduct%2Fdetail%3Fid%3D2008491 这个网站:
```python
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# 创建一个浏览器实例
driver = webdriver.Chrome()
# 打开登录页面
driver.get("https://accounts.gbihealth.com.cn/?returnUrl=https://source.gbihealth.com.cn?redirect=%2Fproduct%2Fdetail%3Fid%3D2008491")
# 等待用户名输入框加载完成
username_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "username"))
)
# 输入用户名和密码
username_input.send_keys("your_username")
password_input = driver.find_element_by_id("password")
password_input.send_keys("your_password")
# 提交表单
password_input.send_keys(Keys.RETURN)
# 等待登录成功页面加载完成
welcome_message = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//span[contains(text(), 'Welcome')]"))
)
# 验证登录是否成功
if "Welcome" in welcome_message.text:
print("登录成功!")
else:
print("登录失败!")
# 关闭浏览器
driver.quit()
```
请确保在运行代码之前,你已经安装了Selenium库,并且下载了适用于你的浏览器的驱动。在上述代码中,我使用的是Chrome浏览器和Chrome驱动。你可以根据需要进行相应的修改。希望对你有所帮助!如果你有任何其他问题,请随时提问。
相关推荐
![js](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)