Selenium-webdriver Series Python Tutorials (3) ———— How to perform a section of JS

Source: Internet
Author: User


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.