任何人都可以查看this html页面。我无法点击此处的“浏览”按钮。 我尝试了以下方法: -
//1st approach
>driver.switchTo().frame(0)
>driver.findElement(By.id("File1")).click
//2nd Approach
>(new Actions).moveToElement(..).sendKeys("Keys.ENTER") // with this i could
//3rd by executing JS in webdriver
>document.findElementById('').value = 'C://.. ' ;
似乎没什么用。有人可以帮忙吗?
答案 0 :(得分:1)
试试这个
driver.switchTo().frame(driver.findElement(By.xpath("//*[contains(@src,'/convert-pdf/default.aspx')]")));
driver.findElement(By.id("File1")).sendKeys("C:\\testFile.xls");
答案 1 :(得分:0)
driver.findElement(By.id("File1")).click
最后遗失了 ()
。iframe
:不安全的JavaScript尝试使用URL访问框架 http://bcldoc2pdflb-1026005913.us-west-1.elb.amazonaws.com/convert-pdf/default.aspx 来自带框架的框架 http://www.pdfonline.com/convert-pdf/default-b.aspx?utm_expid=127285-27&utm_referrer=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F14031004%2Funable-to-click-file-upload-in-webdriver。 域,协议和端口必须匹配。
我已尝试手动(通过浏览器的开发工具中的JavaScript控制台)获取元素,但无法访问iframe:
f = document.evaluate("//*[contains(@src,'/convert-pdf/default.aspx')]", document, null, XPathResult.ANY_TYPE, null)
XPathResult
ifr = f.iterateNext()
<iframe src="http://bcldoc2pdflb-1026005913.us-west-1.elb.amazonaws.com/convert-pdf/default.aspx" width="460px" height="670px" frameborder="0">…</iframe>
ifr.contentDocument
Unsafe JavaScript attempt to access frame with URL http://bcldoc2pdflb-1026005913.us-west-1.elb.amazonaws.com/convert-pdf/default.aspx from frame with URL http://www.pdfonline.com/convert-pdf/default-b.aspx?utm_expid=127285-27&utm_referrer=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F14031004%2Funable-to-click-file-upload-in-webdriver. Domains, protocols and ports must match.
null
d = ifr.contentWindow.document
Unsafe JavaScript attempt to access frame with URL http://bcldoc2pdflb-1026005913.us-west-1.elb.amazonaws.com/convert-pdf/default.aspx from frame with URL http://www.pdfonline.com/convert-pdf/default-b.aspx?utm_expid=127285-27&utm_referrer=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F14031004%2Funable-to-click-file-upload-in-webdriver. Domains, protocols and ports must match.
答案 2 :(得分:0)
在IDE中未标识帧。可能的方法是使用&#34; AutoIT&#34;。我试过了,它成功了。以下是自动
的示例代码 Send("{ENTER}")
Sleep(1000)
Send("D:\questiontovetri.txt")
Sleep(1000)
Send("{TAB}")
Sleep(1000)
Send("{TAB}")
Sleep(1000)
Send("{ENTER}")
Sleep(1000)
Send("{TAB}")
Sleep(1000)
Send("{TAB}")
Sleep(1000)
Send("{TAB}")
Sleep(1000)
Send("{TAB}")
Sleep(1000)
Send("{ENTER}")
Sleep(1000)
要使用autoIT,您需要下载它。参考&#34; http://veera-myseleniumblog.blogspot.com/2011/11/handling-authentication-dialog-box.html&#34;寻求帮助
一旦转换了autoIT脚本,就可以在java代码中调用exe,如
driver.get("http://www.pdfonline.com/convert-pdf/");
driver.findElement(By.xpath("//a[contains(text(),'Upload a File to Convert...')]")).click();
Runtime run = Runtime.getRuntime();
Process pp=run.exec("D:\\blog.exe");
Thread.sleep(5000);
driver.findElement(By.xpath("//a[contains(text(),'Download PDF file')]")).click();
这是有效的,我已经测试了它