Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

322
Views
How to delete DOM element from Selenium Java

I am trying to delete an element from a website using Selenium and Java, I have the xpath of the element

WebElement m = driver.findElement (By.xpath ("//*[contains(text(),'discord.gg/')]"));

Thats the element I have. I want to delete it. I tried

$("//*[contains(text(),'discord.gg/')]").remove();

But that doesnt work either.

Thanks

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I used selenium only in python, and in there I used method to execute javascript in the driver context. Try this. Inside javascriptExecutor run this javascript (change accordingly):

var badTableEval = document.evaluate (
    "//body/center/center/table",
    document.documentElement,
    null,
    XPathResult.FIRST_ORDERED_NODE_TYPE,
    null
);

if (badTableEval  &&  badTableEval.singleNodeValue) {
    var badTable  = badTableEval.singleNodeValue;
    badTable.parentNode.removeChild (badTable);
}
about 4 years ago · Juan Pablo Isaza Report

0

Try this:

WebElement m = driver
    .findElement (By.xpath ("//*[contains(text(),'discord.gg/')]"));
JavascriptExecutor js = (JavascriptExecutor)driver; 
js.executeScript("arguments[0].remove();", m);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!