我是自动化的新手,并试图自动化一个带有链接的网站。当我尝试对用户名和密码进行硬编码,然后使用 Link_text 选择链接时,代码有效,但是当我尝试从 Excel 文件中获取用户名和密码的数据时,用户名和密码字段有效,但链接没有被选中. 有人可以帮忙吗?
这是代码
import XLutils
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(r'C:\Users\test\AppData\Local\Programs\chromedriver_win32\chromedriver.exe')
driver.get("https://test.com")
driver.maximize_window()
path = r'C:\Users\test\Desktop\Reports Test.xlsx'
rows = XLutils.getRowCount(path, 'Login')
username = XLutils.readData(path, "Login", 2, 1)
password = XLutils.readData(path, "Login", 2, 2)
driver.find_element(By.ID, 'username').clear()
driver.find_element(By.ID, 'username').send_keys(username)
driver.find_element(By.ID, 'password').clear()
driver.find_element(By.ID, 'password').send_keys(password)
driver.find_element(By.XPATH, '/html/body/app-root/body/div/app-login/div\[2\]/div\[2\]/form/div\[4\]/button').click()
driver.find_element(By.LINK_TEXT, 'Offer Activity').click()
html
<a class="reportLink" href="null"> Offer Activity </a>