简体   繁体   English

如何使用 selenium java 上传文件

[英]How to upload file using selenium java

I have a question, I want to upload a file in a popup window that is open in my web application.我有一个问题,我想在 web 应用程序中打开的弹出窗口 window 中上传一个文件。

  1. I can not inspect the element of the popup window, window that is opened (F12 not response in this window)我无法检查打开的弹出窗口 window、window 的元素(F12 在此窗口中没有响应)

  2. I try this solutions that not worked我尝试了这个不起作用的解决方案

    WebDriver deiver2 = getWebDriver(); Thread.sleep(8000); Alert alert = deiver2.switchTo().alert(); alert.sendKeys("yyyyy");

the second attemp is:第二次尝试是:

WebDriver deiver2 = getWebDriver();
        Thread.sleep(8000);
        deiver2.switchTo()
                .activeElement()
        .sendKeys(
                "yyyyy");
        System.out.println("END");

In the first attempt it says that no alert exists.在第一次尝试中,它说不存在警报。 In the second attempt it passed but I do not see it feel value in the text field (still blank), How I can upload a file in selenium via popup.在第二次尝试中它通过了,但我在文本字段中看不到它的价值(仍然为空白),如何通过弹出窗口在 selenium 中上传文件。 (and how to inspect the path field to locate the element in the new popup?) (以及如何检查路径字段以在新弹出窗口中定位元素?)

this is the popup screen.这是弹出屏幕。 在此处输入图像描述

this is what solved it这就是解决它的方法

deiver2.switchTo()
                .activeElement();
        System.out.println("Window title: "+ deiver2.getTitle());

        deiver2.findElement(By.xpath("//input[@type='file']"))
        .sendKeys(
                "X:\\AutomationFiles\\yyyyy.pdf");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM