Selenium WebDriver不能控制Kayak网站的隐私框。

huangapple go评论69阅读模式
英文:

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.

英文:

Selenium WebDriver不能控制Kayak网站的隐私框。

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。以下是一些可帮助入门的资源:

英文:

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 -->

&lt;button role=&quot;button&quot; class=&quot;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&quot; tabindex=&quot;0&quot; aria-disabled=&quot;false&quot;&gt;&lt;div class=&quot;Iqt3-button-container&quot;&gt;&lt;div class=&quot;Iqt3-button-content&quot;&gt;No thanks&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;Iqt3-button-focus-outline&quot;&gt;&lt;/div&gt;&lt;/button&gt;

<!-- end snippet -->

You just have to click the following [tag:xpath]:

//button[contains(., &quot;No thanks&quot;)]

in the Dev Tools:

$x(&#39;//button[contains(., &quot;No thanks&quot;)]&#39;)[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:

huangapple
  • 本文由 发表于 2023年5月21日 03:54:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76297096.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定