Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何处理Selenium Python中出现的弹出窗口_Python 3.x_Selenium_Selenium Webdriver_Automation_Browser Automation - Fatal编程技术网

Python 3.x 如何处理Selenium Python中出现的弹出窗口

Python 3.x 如何处理Selenium Python中出现的弹出窗口,python-3.x,selenium,selenium-webdriver,automation,browser-automation,Python 3.x,Selenium,Selenium Webdriver,Automation,Browser Automation,所以我遇到了一个问题,我试图在没有API的应用程序上自动导入。 因此,我必须做30次导航点击才能得到我想要的(夸张)。 然而,我正在尝试基本上自动化的点击,这将允许我上传一个特定的文件。 因此,我几乎到达了必须选择要导入文件的特定测试构建的部分。有一个字段我需要执行send_keys,以找到需要上传的正确导入版本。Field元素如下所示 <input class="lookupInput" type="text" name="brTestScoreImportLookupInput" id

所以我遇到了一个问题,我试图在没有API的应用程序上自动导入。 因此,我必须做30次导航点击才能得到我想要的(夸张)。 然而,我正在尝试基本上自动化的点击,这将允许我上传一个特定的文件。 因此,我几乎到达了必须选择要导入文件的特定测试构建的部分。有一个字段我需要执行
send_keys
,以找到需要上传的正确导入版本。Field元素如下所示

<input class="lookupInput" type="text" name="brTestScoreImportLookupInput" id="brTestScoreImportLookupInput" style="width: 100px;" tabindex="1" onkeydown="return lookupKeyPressed(event,&quot;&quot;,&quot;simptbrws000.w&quot;)" origvalue="" det="true" aria-labelledby="" autocomplete="off">
如果您想访问存储库代码的链接,请单击此链接上方的此处。 任何帮助都将不胜感激

    Traceback (most recent call last): File ".\skyward_collegeboard_TSI_import.py", line 115, in
    <module> test_lookup = browser.find_element_by_id("brTestScoreImportLookupInput") File "C:\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 360, in find_element_by_id return self.find_element(by=By.ID, value=id_) File "C:\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py",
      line 976, in find_element return self.execute(Command.FIND_ELEMENT, { File "C:\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py",
      line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="brTestScoreImportLookupInput"]"}
      (Session info: chrome=80.0.3987.122)
Traceback(最后一次调用):文件“\skyward_collegeboard_TSI_import.py”,第115行,在
test\u lookup=browser.find\u element\u by\u id(“brTestScoreImportLookupInput”)文件“C:\Python38\lib\site packages\selenium\webdriver\remote\webdriver.py”,第360行,find\u element\u by\u id返回self.find\u element(by=by.id,value=id)文件“C:\Python38\lib\site packages\selenium\webdriver\remote\webdriver.py”,
第976行,在find_元素中返回self.execute(Command.find_元素,{文件“C:\Python38\lib\site packages\selenium\webdriver\remote\webdriver.py”,第321行,在execute self.error\u handler.check_响应(response)文件“C:\Python38\lib\site packages\selenium\webdriver\remote\errorhandler.py”,
第242行,在check_response raise exception_类(message,screen,stacktrace)selenium.common.exceptions.NoSuchElementException:message:没有这样的元素:无法找到元素:{“method”:“css选择器”,“选择器”:“[id=”brTestScoreImportLookupInput“]”
(会话信息:chrome=80.0.3987.122)

因此,我能够通过使用selenium和pynput的以下方法来实现这一点

# Browser Switches to Window
WebDriverWait(browser,10).until(EC.number_of_windows_to_be(2))
browser.switch_to.window(browser.window_handles[-1])

# Send test_upload and oend Keys
# Field XPATH = //*[@id='brTestScoreImportLookupInput']
test_lookup = browser.find_element_by_id("brTestScoreImportLookupInput")
test_lookup.send_keys(test_upload)

# Press and Release Enter Key
keyboard.press(Key.enter)
keyboard.release(Key.enter)

基本上,我必须切换到弹出窗口。

>“但是我认为我的代码在弹出窗口时无法正确处理它”但是当你运行代码时会发生什么?没有/错误?没有我得到错误。让我把它粘贴到这里没有我得到错误我将把它添加到Question@0buz我已将其添加到问题的底部。元素是否有可能位于
iframe
中?如果您可以发布html源代码,那就好了。但是如果您的元素确实位于iframe中,您可以在找到字段之前,需要先切换到iframe。使用
驱动程序执行此操作。切换到.frame(>>此处的iframe名称或id)
# Browser Switches to Window
WebDriverWait(browser,10).until(EC.number_of_windows_to_be(2))
browser.switch_to.window(browser.window_handles[-1])

# Send test_upload and oend Keys
# Field XPATH = //*[@id='brTestScoreImportLookupInput']
test_lookup = browser.find_element_by_id("brTestScoreImportLookupInput")
test_lookup.send_keys(test_upload)

# Press and Release Enter Key
keyboard.press(Key.enter)
keyboard.release(Key.enter)