Home > front end >  How to get element by tag name or id in python selenium
How to get element by tag name or id in python selenium

Time:05-23

I am trying to get input using python selenium, but it is showing me an error kindly help me to solve this error

inputElement.send_keys(getStock.getStocklFunc()[0])

error

inputElement = driver.find_element(by=By.CLASS_NAME, value='su-input-group')
NameError: name 'By' is not defined. Did you mean: 'py'?

I have tried with this line too but it is showing depreciation error

find_element_by_tag_name

CodePudding user response:

Use this when you want to locate an element by class name. With this strategy, the first element with the matching class name attribute will be returned. If no element has a matching class name attribute, a NoSuchElementException will be raised.

For instance, consider this page source:

<html>
 <body>
  <p >Site content goes here.</p>
</body>
</html>

The “p” element can be located like this:

content = driver.find_element_by_class_name('content')

https://selenium-python.readthedocs.io/locating-elements.html

CodePudding user response:

Make sure you have Selenium.By imported:

from selenium.webdriver.common.by import By

Then run your command:

inputElement = driver.find_element(By.CLASS_NAME, 'su-input-group')

Do not add the "by=" and "value=" portion to the code.

  • Related