Reputation: 103
The command that I use to click on an element in my script is:
mydriver.find_element(By.xpath("/html/body/div[1]/a/img")).click()
The execution of the script returns this error:
Traceback (most recent call last):
File "click.py", line 12, in <module>
mydriver.find_element(By.xpath("/html/body/div[1]/a/img")).click()
AttributeError: type object 'By' has no attribute 'xpath'
How could the problem be fixed ?
Upvotes: 4
Views: 9156
Reputation: 116
You can also use the By class as in the original post, which is not an incorrect way of doing it in python. To do it this way, you must capitalize By.xpath to By.XPATH as shown in this stackoverflow post: Selenium Webdriver Python AttributeError type object has no attribute
I am not sure why it must be done this way, but it is working for me using python 3.6.4.
Upvotes: 3
Reputation: 357
Correct way of doing that in python is :
mydriver.find_element_by_xpath("/html/body/div[1]/a/img").click()
Upvotes: 3