Can't click the login button on this website by using Python Selenium

Viewed 80

Everyone,

I would like to browse the following website by using Selenium.

https://www.kintips.com/tc/kintips-app.html

(please select "ENG" if you can only read English.)

Here is what I wanted to do:

  1. Open the website with Edge.
  2. Click the "User Login" button.
  3. Enter ID and password.
  4. Click "Login".

I was stuck at Step 2. I tried many strategies like find_element_by_class_name and find_element_by_css_selector. But all the responses were "no such element: Unable to locate element".

How do I locate the element for "User Login" button? Please help. Thank you.

from selenium import webdriver

browser = webdriver.Edge()

#step 1
browser.get('https://kintips.com/tc/kintips-app.html')

#step 2, click a button
current = browser.find_elements_by_class_name('button-inner')
1 Answers

The login button is contained in a iframe webelement (to view it open the browser inspector tool and search //iframe) that's why it gives you the error "no such element: Unable to locate element". First you have to switch to the iframe, and then you can find the element, as shown in the code below

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

browser = webdriver.Edge()

browser.get('https://kintips.com/tc/kintips-app.html')

# pause 30 seconds to let the page load fully, you can reduce or increase this value to your needs
time.sleep(30)

WebDriverWait(browser, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[src*='iads001']")))
login_button = browser.find_element(By.CSS_SELECTOR, "button[class*='login']")
login_button.click()
Related