0

I am trying to get the ID of a web element that contains the word 'Search'. After doing some research I got this:

elementid = driver.find_element_by_xpath("//*[contains(text(), 'Search')]").__getattribute__("id")

The ID that should be returning is 'header-search-bar' but I get this: 1f7b49b1-1f8c-4a38-b466-a7eca3d2ff0b

What did I do wrong? What is the meaning of the string that is being returned?

1
  • We can't possibly know on what kind of input are you trying this. Can you append it to your question ? Commented Mar 19, 2021 at 0:22

2 Answers 2

1

try to use get_attribute instead getattribute:

elementid = driver.find_element_by_xpath("//*[contains(text(), 'Search')]").get_attribute("id")
Sign up to request clarification or add additional context in comments.

12 Comments

I tried that but it returns an empty string.
@EvanMiller try .get_attribute('value')
@EvanMiller make screenshort of your element and it's value, please
<input class="gNO89b" value="Google Search" aria-label="Google Search" name="btnK" type="submit" data-ved="0ahUKEwjCovmIzbrvAhWORjABHSTFBHAQ4dUDCA0">
There is not 'header-search-bar' . Vova tried as he could.
|
0

You are probably talking about a different attribute - data-ved. There is no attribute id. Also, as I understand, you want to get text. Try the following:

your_attribute = driver.find_element_by_css_selector(".gLFyf.gsfi").get_attribute("data-ved")

To get text:

yout_text = driver. find_element_by_css_selector(".gLFyf.gsfi").text

Or

your_text = driver.find_element_by_css_selector(".gLFyf.gsfi").get_attribute("value")

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.