How to click on a link which should be open in same window using Selenium Java

I’m just self studying and trying to Automate the Flipkart site using Selenium- Java.

So here’s the scenario: I want to click on a product link whose attribute is set as Target=_blank.

I want to set it as _self.

I have written one code using JS Executor but getting error in Runtime :

WebElement linkpath = driver.findElement(By.xpath("//div[text()=’vivo Y12G (Glacier Blue, 64 GB)’]"));

JavascriptExecutor js = (JavascriptExecutor) driver;

js.executeScript("document.getElementByXpath("+linkpath+").setAttribute(‘target’, ‘self’)");;


org.openqa.selenium.JavascriptException: javascript error: Unexpected token ‘:’

Source: JavaSript – Stack Overflow

November 14, 2021
Category : News
Tags: Automation | java | javascript | selenium | testing

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.