简体   繁体   中英

Selenium Python library can't find elements on login page

I am attempting to make a web scraper for the Cisco Webex control hub. Since the login page and subsequent pages use Javascript I am using the Selenium Python library to accomplish this. Unfortunately, I am unable to find the text box and sign in button elements with Selenium.

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

# ブラウザを開く。
driver = webdriver.Chrome()
driver.get('https://admin.webex.com')

driver.find_element_by_class_name('md-input ng-pristine ng-invalid ng-touched').send_keys('email@address.com')

driver.find_element_by_class_name('md-panel__cta').click()

I don't have much code yet, but I have tried every way to find the elements, but nothing I tried has worked. Is there any reason why I can't find the elements?

I have moved on ahead and finished the code for the password entry page. However, how Cisco has made each page is different so I was unable to reuse the code from the password entry section on the username entry code.

when an element has more than one class, it will not be a good idea to locate element with class like this find_element_by_class_name('md-input ng-pristine ng-invalid ng-touched') .

In this case, xpath or cssSelector is a good choice:

driver.find_element_by_xpath("//input[@name='email']")

Your issue was page loading. Induce some waits or you'll miss the element.

WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "input.md-input"))).send_keys("email@address.com")

Import

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM