英文:
How to click on the X element to close the email subscription popup
问题
我试图通过点击X按钮来关闭这个电子邮件订阅弹窗。我尝试使用xpath来选择它,但没有成功。
代码尝试:
driver.findElement(By.xpath("/html/body/div[27]/div/div/div/div/div/div/button/svg/circle")).click();
元素快照:
任何帮助将不胜感激。
英文:
I'm trying to close this email subscription popup by clicking on the X. I tried using xpath to select it but I've been unsuccessful.
Code trial:
driver.findElement(By.xpath("/html/body/div[27]/div/div/div/div/div/div/button/svg/circle")).click();
Element snapshot:
Any help would be appreciated.
答案1
得分: 0
在你的情况下,唯一的选择器是 [role=dialog] button[aria-label*=Close]
WebDriverWait wdwait = new WebDriverWait(driver, 10);
driver.get("https://www.marksdailyapple.com/");
wdwait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("[role=dialog] button[aria-label*=Close]"))).click();
英文:
In your case unique selector is [role=dialog] button[aria-label*=Close]
<!-- begin snippet: java hide: false console: true babel: false -->
<!-- language: lang-java -->
WebDriverWait wdwait = new WebDriverWait(driver, 10);
driver.get("https://www.marksdailyapple.com/");
wdwait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("[role=dialog] button[aria-label*=Close]"))).click();
<!-- end snippet -->
答案2
得分: 0
以下是您要翻译的内容:
"The element <kbd>X</kbd> within the email subscription popup is a SVG element.
Solution
To click on the svg element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following locator strategies:
-
Using cssSelector:
driver.get("https://www.marksdailyapple.com/#axzz3HChquQM8"); new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[aria-label='Close form 3'] > svg > path"))).click();
-
Using xpath:
driver.get("https://hausrat.allianz.de/"); new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@aria-label='Close form 3']//*[name()='svg']//*[name()='path']"))).click();
-
Browser snapshot:
"
英文:
The element <kbd>X</kbd> within the email subscription popup is a SVG element.
Solution
To click on the svg element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following locator strategies:
-
Using cssSelector:
driver.get("https://www.marksdailyapple.com/#axzz3HChquQM8"); new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[aria-label='Close form 3'] > svg > path"))).click();
-
Using xpath:
driver.get("https://hausrat.allianz.de/"); new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@aria-label='Close form 3']//*[name()='svg']//*[name()='path']"))).click();
-
Browser snapshot:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论