Change the target attribute of a link from blank to self | Selenium Forum
M
Posted on 22/08/2016
Hi Ashish,

how xpath can be used here instead of id
js.executeScript("document.getElementById('//id of element').setAttribute('target', 'self');");
I need to change the target attribute of a link from blank to self so that the link opens in the same tab and then need to click on it
This is the element:
[code:2a8fasc0]WebElement element = driver.findElement(By.xpath("//a[contains(@href, '/athena/bir/download/export')]"));[/code:2a8fasc0]
i got something like this online
[code:2a8fasc0]WebDriver driver; // Assigned elsewhere
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementByID('//id of element').setAttribute('attr', '10')")[/code:2a8fasc0];
http://stackoverflow.com/questions/19934703/how-to-use-javascript-to-set-attribute-of-selected-web-element-using-selenium-we/19934852#19934852
but i am not able to implement this
plz help

M
Replied on 22/08/2016

xpath cannot be used js executor.


M
Replied on 22/08/2016

I need to change the target attribute of a link from blank to self, can I do this through selenium or java while the script is running?


M
Replied on 23/08/2016

i'm not able to understand can you please repeat?


M
Replied on 23/08/2016

I am saying can we change the following attribute value of target from '_blank' to '_self' through selenium or java while the script is runnning so that the link opens in the same tab instead of opening in the new tab
[code:29zu37i6]<a target="_blank">[/code:29zu37i6]


M
Replied on 23/08/2016

can't make changes to webpage.