如何单击Element()并在同一个选项卡中打开链接,而不是在新窗口中? [英] How to clickElement() and open the link in the same tab, not in a new window?

查看:29
本文介绍了如何单击Element()并在同一个选项卡中打开链接,而不是在新窗口中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页中有以下 html 元素:

I have the following html element in my webpage:

<a target="PARENT" href="/bin-din/WebOb/mom.ko/6/wo/asaksdaksjd
/5.1.5.5.33.23.23">View Data Set</a>

我在 Rselenium 中使用以下命令来查找该标签:

I use the following command in Rselenium to find that tag:

webElem<-remDr$findElement(using = 'xpath',"/html/body/div/table/tbody/tr/td/table[2]
/tbody/tr/tbody/tr/td/font/a[1]")

然后我用下面的命令点击链接:

Then I use the following command to click on the link:

webElem$clickElement()

现在链接在新页面中打开,可能是因为 html 标签包含目标=父母".如何在我在 remDr 中的同一个选项卡中打开该链接?有什么建议?谢谢

Now the link opens in a new page, probably because the html tag includes target="PARENT". How can I open that link in the same tab which I am in remDr? Any suggestions? Thanks

推荐答案

首先,您需要通过在 web 元素中注入 javascript 来清除目标属性为空白.

First you need to clear target attribute with a blank by injecting javascript in your web element.

然后你可以点击它,它会在同一个标​​签中打开链接.代码有点像

Then you can sclick on it and it will open link in same tab. the code somehow look like

webElem<-remDr$findElement(using = 'xpath',"/html/body/div/table/tbody/tr/td/table[2]/tbody/tr/tbody/tr/td/font/a[1]")
remDr$executeScript("arguments[0].setAttribute('target', arguments[1]);", list(webElem, ""));
webElem$clickElement()

这篇关于如何单击Element()并在同一个选项卡中打开链接,而不是在新窗口中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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