我是新的自动化,并试图自动化一个网站与它的链接。当我尝试硬编码用户名和密码,然后使用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:UserstestAppDataLocalProgramschromedriver_win32chromedriver.exe')
driver.get("https://test.com")
driver.maximize_window()
path = r'C:UserstestDesktopReports 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>
change
driver.find_element(By.LINK_TEXT, 'Offer Activity').click()
driver.find_element(By.XPATH, "//a[contains(text(), 'Offer Activity')]").click()