If you look at the HTML of the page https://www.google.com and inspect the Search Box WebElement which you have identified as :
find_element_by_xpath("//input[@title='Search']")
The WebElement is defined as follows :
<input class="gsfi" id="lst-ib" maxlength="2048" name="q" autocomplete="off" title="Search" type="text" value="" aria-label="Search" aria-haspopup="false" role="combobox" aria-autocomplete="list" dir="ltr" spellcheck="false" style="border: none; padding: 0px; margin: 0px; height: auto; width: 100%; background: url("data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw%3D%3D") transparent; position: absolute; z-index: 6; left: 0px; outline: none;">
get_attribute("innerHTML")
As per the documentation, Element.innerHTML gets the HTML syntax describing the element's descendants and get_attribute() is defined as follows :
def get_attribute(self, name):
"""Gets the given attribute or property of the element.
This method will first try to return the value of a property with the
given name. If a property with that name doesn't exist, it returns the
value of the attribute with the same name. If there's no attribute with
that name, ``None`` is returned.
Values which are considered truthy, that is equals "true" or "false",
are returned as booleans. All other non-``None`` values are returned
as strings. For attributes or properties which do not exist, ``None``
is returned.
:Args:
- name - Name of the attribute/property to retrieve.
Example::
# Check if the "active" CSS class is applied to an element.
is_active = "active" in target_element.get_attribute("class")
"""
Hence, as the WebElement i.e. Search Box doesn't have a descendant, so get_attribute('innerHTML') returns empty
innerHTML` andinnerTextnot work with Python in Selenium. For example, when automating IE through VBA I can printinnerHTMLwithgetAttribute("innerHTML")without a problem.innerText()butgetAttribute("innerHTML")is proven, powerful and working when used in proper context. However I don't understand the line/xpathfind_element_by_xpath("//input[@title='Szukaj']")from your code while I can't see the context oftextboxin your code as well.find_element_by_xpath("//input[@title='Search']")locates the input box on Google. I want to print itsinnerHTML.