Selenium Webdriver Control operation (Python)

Source: Internet
Author: User

Unlike the "HTML element Positioning " Article, this article mainly records the various control operations of selenium.

1. Modify page element properties.

Requirements Scenario: Take the <a> tag as an example, when we don't want the new tab or window to open the link, we need to modify the <a> target property to _self.

Solution: It seems that Webdriver does not change the original information of the page, but it provides an interface that can manipulate JavaScript scripts, which can modify the attributes of the elements smoothly.

Specific implementations: driver.execute_script (script, *args)

1 defExecute_script (self, script, *args):2         """3 synchronously executes JavaScript in the current window/frame.4 5 : Args:6 -Script:the JavaScript to execute.7 -\*args:any applicable arguments for your JavaScript.8 9 : Usage:Ten driver.execute_script (' Document.title ') One         """ A         ifLen (args) = = 1: -Converted_args =Args[0] -         Else: theConverted_args =list (args) -Converted_args =list (args) -         returnSelf.execute (Command.execute_script, -{'Script': script,'args': Converted_args}) ['value']

Eg:browse.execute_script ("arguments[0].target= ' _self '", a)

Selenium Webdriver Control operation (Python)

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.