开发者

Checking the contains of an embed tag using Selenium

We generate a pdf doc via a call to a web service that returns the path to the generated doc. We use an embed html tag to display the pdf inline, i.e.

<div id="ctl00_ContentPlaceHolder2_ctl01_embedArea">
        <embed wmode="transparent" src="http://www.company.com/vdir/folder/Pdfs/file.pdf" width="710" height="400"/>

I'd like to use selenium to check that the pdf is actually being displayed and if possible save the path, i.e. the src link into a variable.

Anyone know how to do this? Ideally we'd like to be able to then compare this 开发者_Python百科pdf to a reference one but that's a question for another day.


As far as inspecting the pdf from selenium, you're more or less out of luck. The embed tag just drops a plugin into the page, and because a plugin isn't well represented in the DOM, Selenium can't get a very good handle on it.

However, if you're using Selenium-RC you may want to consider getting the src of the embed element, then requesting that URL directly and evaluating the resulting PDF in code. Assuming your embed element looks like this <embed id="embedded" src="http://example.com/static/pdf123.pdf" /> you can try something like this

        String pdfSrc = selenium.getAttribute("embedded@src");

Then make a web request to the pdfSrc url and do (somehow) validate it's the one you want. It may be enough to just check that it's not a 404.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜