0
votes

Dear Stackoverflowers,

I'm trying to automate a CC payment process but Selenium is having a hard time identifying a specific element I want to click on. I'm trying to click on 'REI Card - 6137' so that I can continue to the payment page. Using the inspect tool it shows the class as, "soloLink accountNamesize". Unfortunately, there's not an ID I can go after. When I try to search by class name I get this error in the console:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .soloLink accountNamesize

Below is a picture of the site and the inspector pane with the thing I'm trying to click on highlighted in blue. Since its my credit card and I'm already logged it a link to the page wouldn't really help you guys.

enter image description here

The script gets hung up on "driver.find_element_by_class_name('soloLink accountNamesize').click()"

My code is below:

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()

I've tried searching by Xpath and Xpath + Class with no luck. I also tried searching for this issue but its a fairly unique class so I didn't have much luck. Have any other ideas I could try?

2
Instead of time.sleep use webdriver waits.Arundeep Chohan

2 Answers

1
votes

soloLink accountNamesize is multiple class names use the following css selector instead to click on that element.

driver.find_element_by_css_selector('a.soloLink.accountNamesize').click()

To induce waits we do

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.soloLink.accountNamesize"))).click()
0
votes

Based on the photo, I think that this is the xpath that you might want

//div[@id='MyAccountsDiv']//div[@id='CreditsTableDiv']//tbody//tr[@class='accountRowFirst']//a[contains(@onclick, 'OpenAccountDashboard')]

As you can see, this xpath starts off with the top-most div that might be unique ( MyAccountsDiv ) and continues to dive into the HTML code.

Based off of this, you could click on the link with the following code

xpath = "//div[@id='MyAccountsDiv']//div[@id='CreditsTableDiv']//tbody//tr[@class='accountRowFirst']//a[contains(@onclick, 'OpenAccountDashboard')]"
driver.find_element(By.XPATH, xpath).click()

NOTE
Your error says

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [id="aw-personal-id"]

Maybe you can use the above technique and see if you can isolate the xpath for the web element instead.