selenium python can't detect id nor name

selenium python can't detect id nor name

python selenium chrome
selenium python install
selenium python example
install selenium python mac
selenium python framework
selenium python github
selenium python 3
selenium with python - basic to expert

I tried to access a website whit selenium but python cant find the id nor the name. Here is the code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox(executable_path='D:\code\geckodriver.exe')
assert "教务系统" in browser.title

def login():
    elem = browser.find_element_by_name('txtUserName')
    elem = browser.find_element_by_name('txtPassWord')

def search():
    elem2 = browser.find_element_by_name('txtFind')


And the html of the website I am accessing:

<form name="search" method="post" action="">
  <input name="txtFind" id="txtFind" type="text">
  <input name="button" id="button" value="搜寻" type="submit">

NOTE the password isn't correct due to some privacy problems.

BTW this thread have been solved, thank you everyone

Replace this code :

def search():
    elem2 = browser.find_element_by_name('txtFind')

To this :

def search():
    elem2 = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, "txtFind")))

Note that if ID is given , then there is no need to go for any locator.

2. Getting Started, The above script can be saved into a file (eg:- ), then it WebDriver will wait until the page has fully loaded (that is, the “onload” event  The easiest way to install Selenium on a Python environment is through the installer pip. pip install selenium. While the installation of Selenium makes the functionality available to you, you need additional drivers for it to be able to interface with a chosen web browser. The download links for the drivers are available here: Chrome, Edge

You've only posted some of the html. One option is that the locators for the login aren't valid. The other option is that the program begins looking for the elements before the page is loaded. In this case the exception would state that the element was not found.

I had a similar issue and what worked for me was to place an explicit wait on the first element I would be searching for in the new page. An explicit wait waits a specified amount of time for a specified condition to be met.

For example: element = WebDriverWait(driver, seconds).until(EC.presence_of_element_located(By.NAME, 'txtuserame'))

Alternatively you can use an implicit wait which ideally causes the driver to wait a specified amount of time if the page hasn't loaded. In my experience it's very dependent on the website and it often doesn't work as intended.

An example of an implicit wait in python would be driver.implicitly_wait(10) Implicit wait relates to the driver rather than the element, and remain in effect for the lifespan of the driver instance.

You can find more info about wait over here and you can find a list of expected conditions that you can use with explicit wait here.

1. Installation, Through Selenium Python API you can access all functionalities of Selenium WebDriver in an intuitive way. Selenium Python bindings provide a convenient API to  Selenium is mostly used for writing test cases. The selenium package itself doesn’t provide a testing tool/framework. You can write test cases using Python’s unittest module. The other options for a tool/framework are py.test and nose. In this chapter, we use unittest as the framework of choice. Here is the modified example which uses

Selenium with Python, Today you will use a full-fledged browser running in headless mode to do the HTTP requests for you. A headless browser is just a regular web browser, except that  pip install -U selenium And use this module in your code . from selenium import webdriver You can also use many of the following as required . from import By from import Select from selenium.common.exceptions import NoSuchElementException Here is an updated answer

Modern Web Automation With Python and Selenium – Real Python, You can then decide if the response of the browser is in line with what you expect​. This post assumes that you do not have prior knowledge of  By using Python with Selenium, you can launch the browser of your choice, fetch any webpage, programmatically click links, fill out web forms, and use other browser functions like back, forward, and reload. Selenium is very powerful and facilitates more flexibility than web scraping tools like Beautiful Soup and Scrapy.

Selenium Python Bindings, Installing. If you have pip on your system, you can simply install or upgrade the Python bindings: pip install -U selenium. Alternately, you can download the  Here are a few quick ideas that would leverage the mild superpower that is Python + Selenium: You could extend the BandLeader class to navigate to album pages and play the tracks you find there. You might decide to create playlists based on your favorite or most frequently heard tracks.

Proboscis, Selenium WebDriver is the one that can automate all these tasks. It can interact with all types of Web browsers available till date like Firefox, Internet Explorer,  Python language bindings for Selenium WebDriver. The selenium package is used to automate web browser interaction from Python.