Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7081781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:57:51+00:00 2026-05-28T06:57:51+00:00

Page has image with hyperlink and that hyperlink has target=_blank and every time i

  • 0

Page has image with hyperlink and that hyperlink has target=”_blank” and every time i press that image loads new firefox and that hyperlink is redirected to that new firefox web
and i lose all control of that webpage.
Is possilble to remove or change that target=”_blank” on hyperlink, bcause i want to load webpage in same webdriver

WebDriver driver = new FirefoxDriver();

    driver.get("http://www.page.eu/");
    WebElement submit;
    submit = driver.findElement(By.xpath("//img[@alt='page']"));
    submit.click();

that hyperlink have target=”_blank”
i need to change that target somehow by using webdriver + javascript maybe or what?
is it possible?

edited

thanks for suggestions, but still is this problem
i tried to make like Grooveek said but no changes

WebElement labels2 = driver.findElement(By.xpath("//a[@href='http://tahtpage.net']"));
    WebElement aa = (WebElement) ((JavascriptExecutor)  driver).executeScript("labels2.setAttribute('target','_self')",labels2 );
    aa.click();

i have an error
org.openqa.selenium.WebDriverException: null (WARNING: The server did not provide any stacktrace information)

i’m not good at javascrit so i think is problem in that executor

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:57:51+00:00Added an answer on May 28, 2026 at 6:57 am

    Try the following:

    WebElement labels2 = driver.findElement(By.xpath("//a[@href='http://tahtpage.net']"));
    WebElement aa = (WebElement) ((JavascriptExecutor) driver).executeScript("arguments[0].setAttribute('target','_self')",labels2 );
    aa.click();
    

    You are getting a null exception because you are using labels2 in your javascript, which doesn’t exist in that context. By changing it to arguments[0] Selenium will take the labels2 parameter and reference it in javascript appropriately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reloading a web page that has the following code: <label for=showimage>Show Image</label> <input
I have a page that has a large image on it with a number
i have a page for a small mobile site that has an image that
I have a cherryPy program that returns a page that has an image (plot)
On this link you can see that the page has a background image, but
I'm creating a simple HTML page that has an image upload. That image then
I need to create a link for an ASP.NET page that has an image
I have a web page that has an HTML table generated by an ASP.NET
I have a product page that has image thumbnails and links bellow for front
Page has menu items that would replace a 'div id=foo_(current menu item)' with 'div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.