1

我在自动化网页时遇到了问题,我在这里找到了它的解决方案。在我的回答中,第二个代码片段是

#Assume that at this point you are on the page where you need to click on a Web Element to      trigger native OS window/dialog box

def _action_on_trigger_element(_element):
    _element.click()

trigger_element = driver.find_element_by_id('ID of the Web Element which triggers the window')
th = threading.Thread(target = _action_on_trigger_element, args = [trigger_element])  #Thread is    created here to call private func to click on Save button
th.start()                          #Thread starts execution here
time.sleep(1)                       #Simple Thread Synchronization handle this case.          

#Call WindowFinder Class
win = WindowFinder()
win.find_window_wildcard(".*Save As.*") 
win.set_foreground()
path = "D:\\File.txt"            #Path of the file you want to Save 
ent = "{ENTER}"                  #Enter key stroke.
SendKeys.SendKeys(path)          #Use SendKeys to send path string to Save As dialog
SendKeys.SendKeys(ent)           #Use SendKeys to send ENTER key stroke to Save As dialog

#At this point the native OS window is interacted with and closed after passing a key stroke ENTER.
# Go forward with what ever your Automation code is doing after this point

当我从 IDE 运行代码时Aptana Studio3,代码运行良好,并且我的线程调用私有函数_action_on_trigger_element(_element),但是当我通过命令行调用Python脚本运行相同的代码时,线程不会调用作为其目标的函数。

我检查了线程还活着。对此和解决方法的任何解释表示赞赏。

谢谢

4

0 回答 0