【发布时间】:2020-11-16 08:50:41
【问题描述】:
亲爱的 Stackoverflowers,
我正在尝试自动化 CC 支付流程,但 Selenium 很难识别我想要点击的特定元素。我正在尝试点击“REI Card - 6137”,以便继续进入付款页面。使用检查工具,它将类显示为“soloLink accountNamesize”。不幸的是,没有我可以追踪的 ID。当我尝试按类名搜索时,我在控制台中收到此错误:
selenium.common.exceptions.NoSuchElementException:消息:无法 定位元素:.soloLink accountNamesize
下面是网站的图片和检查器窗格,其中我尝试单击的内容以蓝色突出显示。由于它是我的信用卡并且我已经记录了它,因此该页面的链接不会真正帮助你们。
脚本挂断在“driver.find_element_by_class_name('soloLink accountNamesize').click()”上
我的代码如下:
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
import yaml
import time
conf = yaml.load(open(r'D:\Users\Matt\Documents\GitHub\YML_Files\REI_Login_Credentials.yml'))
myREIUsername = conf['REILogin']['username']
myREIPassword = conf['REILogin']['password']
driver = webdriver.Firefox(
executable_path=
r'D:\Users\Matt\Documents\GitHub\Executable_Files\geckodriver.exe'
)
def login():
driver.get('https://onlinebanking.usbank.com/Auth/Login?usertype=REIMC&redirect=login&lang=en&exp=')
time.sleep(4)
driver.find_element_by_id('aw-personal-id').send_keys(myREIUsername)
driver.find_element_by_id('aw-password').send_keys(myREIPassword)
time.sleep(2)
driver.find_element_by_id('aw-log-in').click()
time.sleep(15)
make_payment()
def make_payment():
if (driver.find_element_by_class_name("accountRowLast").text) != "0.00":
driver.find_element_by_class_name('soloLink accountNamesize').click()
else:
driver.quit()
我尝试通过 Xpath 和 Xpath + Class 进行搜索,但没有成功。我也尝试搜索这个问题,但它是一个相当独特的课程,所以我没有太多运气。有什么我可以尝试的其他想法吗?
【问题讨论】:
-
使用 webdriver 等待而不是 time.sleep。
标签: python selenium automation