硒点击一个链接,其中href是的javascript:无效[0]; [英] Selenium clicking a link where the href is javascript:void[0];

查看:390
本文介绍了硒点击一个链接,其中href是的javascript:无效[0];的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想看看是否是点击一个链接时,使用硒的webdriver与Java网页上生成的报告。

I'm trying to see if when a link is clicked a report is generated on the page using Selenium webdriver with Java.

会发生什么事是,有一个页面上一堆链接,其中大部分点击时走到哪里我都自动在细节填充和提交表单,检查报告生成另一个页面。

What happens is there are a bunch of links on a page, most of them when clicked go to another page where I have automated filling in the details and submitting the form to check the report is generated.

然而,有三份报告,当点击造成一定的JS运行,几秒钟后,一个新的链接显示在同一页面上下载报告。

However there are three reports that when clicked cause some JS to run and after a few seconds a new link is displayed on the same page to download the report.

我怎么可以点击这个链接?

How I can click this link?

我读网页上的所有链接到WebElements然后通过他们所在的HREF包含的JavaScript循环列表:无效[0];

I am reading all the links on the page into a list of WebElements then looping through them for where the href contains javascript:void[0];

然后我尝试调用该元素的点击方法在列表中,allLinks.get(I)。点击();

I then try calling the click method on that element in the list, allLinks.get(i).click();

这是我的其他报告做同样的事情,它工作正常,但是,这3我得到一个错误
元素当前不可见,因此不得与互动

This is the same thing I do for the other reports and it works fine but on these 3 I get an error "Element is not currently visible and so may not be interacted with"

用Firebug如果我检查了启动JS运行它说的链接:

Using firebug if I inspect the link that starts the JS running it says:

<a onclick="requestReportGeneration('2cad4d4e5c8855c47a88b6ddf8345735', 'reportDiv33','CSV')" href="javascript:void[0];">CSV</a>

任何人都可以提出一个方法来点击链接?

Can anyone suggest a way to click the link?

该页面包含大量的链接,说CSV,所以我不能只是使用链接文本。

The page contains lots of links that say CSV so I cant just use the link text.

更新:
我刚喝了这个可能有助于思想。当我第一次来到该报告的页面链接,它会说订单报告我需要点击标题,然后调用一个JS函数来展开该部分和显示的链接。

UPDATE: I've just had a thought about this which might help. When I first come to the page with the report links it will say "Order reports" I need to click the heading which then calls a JS function to expand that section and display the links.

这工作的工作报告,因为当我来到这个网页,我刚才读的网页源代码中所有的HREF并做driver.get(reportList.get(I)。所以我不实际点击链接

The reports that work work because when I come to this page I just read all the hrefs of the page source and do driver.get(reportList.get(i); so I'm not actually clicking on the link.

我添加了一个链接以获取标题的XPath和单击它但后来当我尝试点击的HREF或JavaScript的链接:虚空我仍然得到一个错误说其不可见。

I have added a link to get the xpath of the heading and click it but then when I try to click the link with the href or javascript:void I still get an error saying its not visible.

推荐答案

有关锚标签包含 HREF =JavaScript的:这样使用本地JavaScript click()方法

For anchor tags that contain href="javascript:" use native javascript click() method like this:

WebElement wwwLink = ((FindsByCssSelector) webDriver)
                .findElementByCssSelector("table[id='initiatorsTable'] tbody tr:not([class^='empty']) td[class='first'] a");

JavascriptExecutor exec = (JavascriptExecutor) webDriver;
exec.executeScript("arguments[0].click()", wwwUrl);

//TODO: wait for action code ...

这篇关于硒点击一个链接,其中href是的javascript:无效[0];的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆