Python + Selenium webdriver using Python to simulate mouse, keyboard operation, to solve swffileupload call system Bottom Popup cannot locate the problem

Source: Internet
Author: User

Webdriver is a browser-based operation, when the page upload file is used by the Flash control Swffileupload call, the system is called the bottom of the file selection pop-up box

In this case, Webdriver temporarily does not support actions other than the page

Many methods have been tried before, such as Send_keys ("path"), but none of them can be solved

Although Webdriver cannot operate on the underlying, Python extensions are possible

By simulating mouse, keyboard operation, you can solve this problem, but this method is more stupid, and not ideal, if there is a good way, please leave a message to me, thank you!

Workaround:

1. Extend Python Package

To operate on the underlying, you need to import Win32api,win32con

Download the two modules directly and install them

2, in Python to achieve mouse positioning, click, keyboard input operation

PS: In the file selection pop-up box to locate, click, in my operating system, there is no click, but in the colleague's computer can operate, so I took the analog keyboard input file name, to ensure that the file can be uploaded correctly

The role of time is important to play a buffering role, if the loading speed is slow, without adding time, it may cause this method to fail

① Analog Keyboard input (note the location of the file)

ImportWin32conImportWin32API fromcTYPESImport*Import TimedefMouse_click (x, y):#set Mouse initial sitWindll.user32.SetCursorPos (x, y) win32api.mouse_event (Win32con. Mouseeventf_rightdown, 0, 0, 0, 0)#left mouse button clickTime.sleep (1) win32api.keybd_event (65,0,0,0)#A keying code is aWin32api.keybd_event (65, 0,win32con. keyeventf_keyup,0) win32api.keybd_event (65,0,0,0)#A keying code is aWin32api.keybd_event (65, 0,win32con. keyeventf_keyup,0) win32api.keybd_event (110,0,0,0)#. The keying code isWin32api.keybd_event (110, 0,win32con. keyeventf_keyup,0) win32api.keybd_event (74,0,0,0)#J Keying code is 106Win32api.keybd_event (74, 0,win32con. keyeventf_keyup,0) win32api.keybd_event (80,0,0,0)#p keying code isWin32api.keybd_event (80, 0,win32con. keyeventf_keyup,0) win32api.keybd_event (71,0,0,0)#g keying code is 103Win32api.keybd_event (71, 0,win32con. keyeventf_keyup,0) Time.sleep (1) win32api.mouse_event (Win32con. Mouseeventf_rightup, 0, 0, 0, 0)#left mouse button releaseTime.sleep (1) win32api.keybd_event (13,0,0,0)#Enter keying codeWin32api.keybd_event (13, 0,win32con. keyeventf_keyup,0) win32api.keybd_event (13,0,0,0)#Enter keying codeWin32api.keybd_event (13, 0,win32con. keyeventf_keyup,0) Time.sleep (1)

② analog mouse Positioning selection file

def mouse_double_click (x, y): Windll.user32.SetCursorPos (x, y) win32api.mouse_event (Win32con. mouseeventf_leftdown,0,0,0,0) win32api.mouse_event (Win32con. Mouseeventf_leftup, 0, 0, 0, 0)  # left mouse button released Win32api.mouse_event (Win32con. mouseeventf_leftdown,0,0,0,0) win32api.mouse_event (Win32con. Mouseeventf_leftup, 0, 0, 0, 0)  # left mouse button release

In fact, the two methods are similar, the second method is actually double-click effect

---restore content ends---

Python + Selenium webdriver using Python to simulate mouse, keyboard operation, to solve swffileupload call system Bottom Popup cannot locate the problem

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.