Reputation: 55
I have the following span class:
<span class="k-pager-info k-label">1 - 25 of 93995 items</span>
and its Xpath is
//*[@id="registerGrid"]/div[3]/span
I would like to get the number 93995 out.
I have tried the following:
driver.findElement(By.xpath("""//*[@id="registerGrid"]/div[3]/span""")).getText()
Traceback (most recent call last):
File "<pyshell#47>", line 1, in <module>
driver.findElement(By.xpath("""//*[@id="registerGrid"]/div[3]/span""")).getText()
AttributeError: 'WebDriver' object has no attribute 'findElement'
What shall I do then?
Upvotes: 1
Views: 10509
Reputation: 2523
Syntax error: Use driver.find_element
instead of driver.findElement
from selenium.webdriver.common.by import By
element = driver.find_element(By.XPATH, '//*[@id="registerGrid"]/div[3]/span')
text = element.text
Refer selenium docs for locating the elements
Upvotes: 4
Reputation: 27503
from selenium.webdriver.common.by import By
driver.find_element(By.XPATH, '//*[@id="registerGrid"]/div[3]/span')
you made a mistake it will be find_element and text only not getText()
driver.find_element(By.XPATH, '//*[@id="registerGrid"]/div[3]/span').text
Upvotes: 2