print(driver.execute_script('return document.title')) print(driver.execute_script('return document.URL'))
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)
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 title of page in console print(driver.execute_script('return document.title')) # get the URL of page in console print(driver.execute_script('return document.URL')) #to close the browser driver.close()