尝试访问网址并在打开网址时,会生成一个提醒,需要点击取消标签/关闭提醒。然后,它才会被重定向到网址。我使用switch_to_alert()来实现这一点。但是,它不起作用。
Edit1:根据使用AutoIT的建议,更新脚本以运行autoscript.exe文件。
AutoIT代码:
MouseMove ( 1012, 320 [, speed = 10] ) #position of the button to be clicked on the alert
MouseClick ( "$MOUSE_CLICK_LEFT" [, 1012, 320 [, clicks=1 [, speed = 10]]] )
使用生成.exe文件的CompileScript(x64)编译上面的代码。
代码:
from selenium import webdriver
browser=webdriver.Chrome()
url='my-url'
browser.maximize_window()
browser.get(url)
browser.implicitly_wait(5)
exec(open("click.exe").read()) #running the generated auto.exe file
错误:
它不起作用并以下面的错误终止。
File "popup.py", line 16, in <module>
exec(open("click.exe").read())
File "C:\Users\test\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py", line 23, in decode
0920/150119.844:ERROR:gles2_cmd_decoder.cc(17788)] [.DisplayCompositor-000000000D86FDD0]GL ERROR :GL_INVALID_OPERATION : glCreateAndConsumeTextureCHROMIUM: invalid mailbox name
0920/150119.853:ERROR:gles2_cmd_decoder.cc(9798)] [.DisplayCompositor-000000000D86FDD0]RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible textur
filtering.
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
nicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 2: character maps to <undefined>
答案 0 :(得分:0)
使用显式或隐式等待,直到元素存在,然后尝试关闭警报。
wait = WebDriverWait(self.driver, 10)
element = wait.until(EC.element_to_be_clickable((locator)))