当代码通过IDE和命令提示符运行时,Python线程行为不同
我在自动化一个我找到解决方案的网页时遇到了一个问题。 在我的回答中,第二个代码片段是当代码通过IDE和命令提示符运行时,Python线程行为不同,python,windows,multithreading,selenium,command-line,Python,Windows,Multithreading,Selenium,Command Line,我在自动化一个我找到解决方案的网页时遇到了一个问题。 在我的回答中,第二个代码片段是 #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_el
#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
当我从IDEAptana Studio3
运行代码时,代码运行良好,我的线程调用私有函数\u action\u on\u trigger\u元素(\u元素)
但是当我通过调用Python
脚本的命令行运行相同的代码时,线程不会调用作为其目标的函数
我检查过线还活着。对此和解决方法的任何解释都将不胜感激
谢谢这两个场景可能使用不同的环境吗?@Hyperboreus不一样唯一的区别是它们的触发方式。你说的“触发”是什么意思?@Hyperboreus我的意思是唯一的区别是脚本的执行方式。一个是在IDE内部,在这种情况下,它工作正常,只需一次通过命令行,线程从不调用私有函数。