javas = "document.getElementsByName('user-search').click();" driver.execute_script(javas)
Please note, we have used getElementsByName('user-search'). The functions like getElementsByName and getElementsById return an array of matching elements. So for locating the first element, the index is used.However if we are using getElementById function, we need not use the index since only one matching element is referred there.
userN= driver.find_element_by_id("user-search']") driver.execute_script("arguments.click();", userN)
selenium.common.exceptions.WebDriverException − Message − unknown error − Cannot read property 'innerHTML'
Also, there may be scenarios, when an improper action or a faulty name of function is used, for example a spelling error in function. In these cases as well, similar web driver exceptions will be thrown.
print driver.execute_script('return document.title')
from selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke #actual browser driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/index.htm") #to refresh the browser driver.refresh() # get the inner text of page in console print( driver.execute_script('return document.documentElement.innerText')) #to close the browser driver.close()