How to clickElement() and open the link in the same tab, not in a new window?

放肆的年华 提交于 2019-12-07 21:07:31

问题


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>

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()

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


回答1:


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()


来源:https://stackoverflow.com/questions/29908679/how-to-clickelement-and-open-the-link-in-the-same-tab-not-in-a-new-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!