1

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?

4
  • Please format the code Commented May 16, 2017 at 9:28
  • I hope that you are using selenium with python, please use proper syntax Commented May 16, 2017 at 9:47
  • I am using selenium with python... are they not proper syntax? Commented May 16, 2017 at 9:49
  • use text instead of getText() in python Commented May 16, 2017 at 10:05

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for reply... but when I added this with .getText(), I got error message: Traceback (most recent call last): File "<pyshell#52>", line 1, in <module> driver.find_element(By.XPATH, '//*[@id="registerGrid"]/div[3]/span').getText() AttributeError: 'WebElement' object has no attribute 'getText'
2
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

Comments

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.