Sometimes you need to execute a JS script on the page when you are automating the test.
Execute_script method.
From selenium import Webdriver
Browserobj_dirver = Webdriver. Ie ()
Browserobj_dirver.get ("http://www.soso.com")
Browserobj_dirver.implicitly_wait (5)
Browserobj_dirver.execute_script ("q = document.getelementbyidx_x_x (' TB ');" + "Q.style.border = ' 1px solid red ';")
The above code opens the first page of the Soso and highlights the DIV with the id "TB".
The following example shows how to automatically focus to the Soso search box on the page when opening the homepage of the QQ
From selenium import Webdriver
Browserobj_dirver = Webdriver. Ie ()
Browserobj_dirver.get ("http://www.qq.com")
Browserobj_dirver.implicitly_wait (5)
Browserobj_dirver.execute_script ("p = document.getelementbyname (' W ');" + "q.focus ();")
Selenium-webdriver Series Python Tutorials (3) ———— How to perform a section of JS