1

I'm getting this error every time I use FindElement(By.xpath("//... syntax instead of find_element_by_xpath(... etc, telling me that FindElement is not an attribute of webdriver. What form of declaration I have to write down to make it an attribute. I only use:

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

driver = webdriver.Firefox()
driver.get('https://demoqa.com/text-box')

EnterFullName = driver.FindElement(By.xpath('//input[contains(@id,"userName")'])
EnterFullName.send_keys("Daniel Soth")

It is obviously working if I write down this line of code:

EnterFullName = driver.find_element_by_xpath('//*[@id="userName"]')

EnterFullName.send_keys("Daniel Soth")

However I'm intrigued by this FindElement attribute that is simply not working and I would like someone to explain why and what I need to declare in order to make it work.

5
  • 1
    please post the code where you've used FindElement at Commented Oct 24, 2020 at 15:06
  • 1
    find_element is a method over the driver instance. I.e: driver.find_element(By.XPATH, ... ) Commented Oct 24, 2020 at 15:07
  • I really want to use FindElement attribute. I can do it differently but I would like to know how to use the FindElement. thanks Commented Oct 24, 2020 at 15:51
  • I believe it should be something with import org.openqa. selenium.Webdriver and WebElement. There is no such thing as orq.openqa to install. Really foggy right now. Commented Oct 24, 2020 at 15:53
  • To understand that FindElement is a Java attribute that can be used with Selenium package but not with Python? Commented Oct 24, 2020 at 16:53

1 Answer 1

1

FindElement has been named as driver.find_element in the python package (in accordance with python's naming convention).

This is how you use it in python:

enter_full_name = driver.find_element(By.XPATH, "//input[contains(@id,'userName')]")
Sign up to request clarification or add additional context in comments.

8 Comments

Since you told us you were facing FindElement is not an attribute of webdriver error, I only focused on solving that and took the expression as granted :) give me a moment to check that
I believe that's just selenium's java package name. (it's common to use company domain reversed in Java). Don't worry about it if you're only using python
please try the code from the updated answer as is. (without changing quotemarks)
@Daniel please consider upvoting/accepting this answer should you find it useful. It would help a lot
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.