Consider:
<a name="DERIVED_SSS_SCL_SSS_ENRL_CART$276$" id="DERIVED_SSS_SCL_SSS_ENRL_CART$276$" ptlinktgt="pt_peoplecode" tabindex="126" href="javascript:submitAction_win0(document.win0,'DERIVED_SSS_SCL_SSS_ENRL_CART$276$');" class="SSSHYPERLINKBOLDSMALL">Enrollment Shopping Cart</a>
Is the element I want to find.
Background: I'm trying to automate class registration. The page in question must be accessed by some security measures and is definitely not a typical web page.
First, I tried this:
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()
username = input("Username: ")
password = input("Password: ")
username_box = driver.find_element_by_name("j_username")
username_box.send_keys(username)
password_box = driver.find_element_by_name("j_password")
password_box.send_keys(password)
password_box.send_keys(Keys.RETURN) # Now, we are at the page in question after signing on.
I tried this:
to_shopping_cart = driver.find_element_by_link_text("Enrollment Shopping Cart")
with find_element_by_link_text, find_element_by_partial_link_text, find_element_by_id, find_element_by_name and a few other options listed in the documentation on 7. WebDriver API. All of these threw "no such element".
Next, I tried using WebDriverWait. This kept throwing "TimeOut exception".
Current theories:
It has to do with the protected sign in. It's a really strangely built site and is not intuitive at all. There are tons and tons of elements within one another.
It has to do with the other elements around it. I'll definitely upload those if I need to. It's just a huge block of HTML, so I wanted to keep the question as concise as possible for the time being.
I thought about using driver.get() with the href action, but that just reloads the web page. So that doesn't work either.
I solved the problem
By switching to the proper iFrame with:
proper_frame_element = driver.find_element_by_name('TargetContent')
driver.switch_to_frame(proper_frame_element)