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)