英文:
Selenium WebDriver doesn't drive Privacy box in Kayak web site
问题
I test automated a test case in Selenium WebDriver
. The driver opens Kayak UK web site in incognito mode. However, it doesn't drive privacy popup.
I was wondering what line of codes do I need to include to Accept the box? I checked, and the message box is not in an iFrame
. I tested
SwitchTo().Alert().Accept
and it didn't work. Not sure what it is that Web Driver doesn't drive it.
Any tips/suggestions/advice much appreciated.
英文:
I test automated a test case in Selenium WebDriver
. The driver opens Kayak UK web site in incognito mode. However it doesn't drive privacy popup.
I was wondering what line of codes do I need to include to Accept the box? I checked and the message box is not in iFrame
. I tested
SwitchTo().Alert().Accept
and it didn't work. Not sure, what it is that Web Driver doesn't drive it.
Any tips/suggestions/advises much appreciated.
答案1
得分: 0
如果你右键点击No thanks
按钮,然后选择检查元素
,你会看到:
<button role="button" class="Iqt3 Iqt3-mod-stretch Iqt3-mod-bold Button-No-Standard-Style Iqt3-mod-variant-outline Iqt3-mod-theme-base Iqt3-mod-shape-rounded-small Iqt3-mod-shape-mod-default Iqt3-mod-spacing-default Iqt3-mod-size-small" tabindex="0" aria-disabled="false">
<div class="Iqt3-button-container">
<div class="Iqt3-button-content">No thanks</div>
</div>
<div class="Iqt3-button-focus-outline"></div>
</button>
你只需点击以下 [tag:xpath]:
//button[contains(., "No thanks")]
在开发者工具中执行:
$x('//button[contains(., "No thanks")]')[0].click()
这不是一个alert()
弹窗。这就是为什么它失败的原因。
有许多在线资源可供学习XPath
。以下是一些可帮助入门的资源:
- W3Schools 包括了XPath的所有基础知识,并附有合适的示例。
- W3Schools XPath 语法
- Tutorialspoint 解释了XPath的基础知识,适合初学者。
英文:
If you right click on the No thanks
button, then Inspect
, you can see:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<button role="button" class="Iqt3 Iqt3-mod-stretch Iqt3-mod-bold Button-No-Standard-Style Iqt3-mod-variant-outline Iqt3-mod-theme-base Iqt3-mod-shape-rounded-small Iqt3-mod-shape-mod-default Iqt3-mod-spacing-default Iqt3-mod-size-small" tabindex="0" aria-disabled="false"><div class="Iqt3-button-container"><div class="Iqt3-button-content">No thanks</div></div><div class="Iqt3-button-focus-outline"></div></button>
<!-- end snippet -->
You just have to click the following [tag:xpath]:
//button[contains(., "No thanks")]
in the Dev Tools:
$x('//button[contains(., "No thanks")]')[0].click()
This is not an alert()
box. That's why it fails.
There are many resources available online to learn XPath
. Here are some that can helps to get started:
- W3Schools covers all the basics of XPath with suitable examples and...
- W3Schools XPath syntax
- Tutorialspoint explains the basics of XPath and is suitable for beginners.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论