任何方式访问使用Selenium在浏览器中打开的PDF元素

时间:2014-03-26 15:35:11

标签: java pdf selenium browser

实际上我正在使用Selenium自动化一个Web应用程序。我们知道Selenium只能自动化Web应用程序,但在我的应用程序中,某些页面包含加载的PDF文档,我需要与PDF中的按钮进行交互。有没有办法从Selenium做到这一点。如果可能的话请帮帮我。提前致谢。

2 个答案:

答案 0 :(得分:0)

Selenium无法做到这一点。 Selenium自动化浏览器,而不是其中的嵌入式应用程序。

您可以使用Selenium与PDF相关的程度,通过执行简单的assert that by_id("embeddedPDF") is there

验证嵌入对象是否在那里

答案 1 :(得分:0)

这是一个全能的黑客,但可能是在硒中做到这一点的唯一方法。

如果使用具有两个参数的clickAt方法,则元素定位器和坐标:

void clickAt(java.lang.String locator,
             java.lang.String coordString)

Parameters:
locator - an element locator
coordString - specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.

如果将元素定位器设置为PDF的<embed/>对象,并将坐标设置为屏幕上PDF上按钮所在位置。它应该单击PDF中的链接。然而,这是非常不可靠的,但我不确定有更好的方法来做到这一点。