未捕获的DOMException:无法在“节点"上执行"removeChild":要删除的节点不是该节点的子节点 [英] Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node

查看:1169
本文介绍了未捕获的DOMException:无法在“节点"上执行"removeChild":要删除的节点不是该节点的子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次打开时,我的页面上都会出现一个对话框.我想关闭它,以便继续进行编程. 对话框就是这样的图片

I have a dialog box appearing on my page every time I open it. I want to close it so that I can proceed with my programming. The dialogue box is like this image

我尝试了以下代码:

wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("div#psyma_layer_background div#psyma_header div#psyma_close_link_container div#psyma_close_link a#psyma_close_button_link")));

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#psyma_layer_background div#psyma_header div#psyma_close_link_container div#psyma_close_link a#psyma_close_button_link")));

wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div#psyma_layer_background div#psyma_header div#psyma_close_link_container div#psyma_close_link a#psyma_close_button_link"))).click();

我进行了元素检查,可见性和可点击性检查,以确保我不会错过任何元素,但是它无法弄清楚"X"符号,因此无法关闭对话框!如果可以的话,请帮助我,真的很难解决这个问题

I did presence of element check, visiblity and clickability check so that I do not miss the element by any chance but it's not able to figure out the "X" sign and so not closing the dialogue box! Please help me out if you can, really struggling with this one

推荐答案

看来您已经很接近了.要关闭页面上显示的对话框,您需要单击标记为 X 的元素,该元素是<a>标记.因此,要在所需元素上调用click(),您需要等待所需的元素可点击,如下所示:

It seems you were pretty close. To close the dialog box appearing on your page you need to click on the element marked as X which is a <a> tag. So to invoke click() on the desired element you need to wait for the desired element to be clickable as follows:

  • 代码块:

  • Code Block:

System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.landrover.co.uk");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("X"))).click();
System.out.println(driver.getTitle());

  • 控制台输出:

  • Console Output:

    Starting ChromeDriver 2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab) on port 15398
    Only local connections are allowed.
    Jun 18, 2018 2:52:08 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Detected dialect: OSS
    Premium 4x4 Vehicles & Luxury SUVs - Land Rover UK
    

  • 浏览器快照:

  • Browser Snapshot:

    这篇关于未捕获的DOMException:无法在“节点"上执行"removeChild":要删除的节点不是该节点的子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆