如何从Selenium中的Ajax请求获取数据? [英] How to get data from Ajax request in Selenium?

查看:158
本文介绍了如何从Selenium中的Ajax请求获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试检查我的应用程序中的星巴克礼品卡的余额, https://www.starbucks .com/card

I have been trying to check the balances of Starbucks gift cards in my application, https://www.starbucks.com/card

我试图捕获用ajax请求做出的响应,一旦自动单击了余额检查"按钮,如何在Selenium中获得ajax响应?

I was trying to catch the response made with ajax request, once check balance button is clicked automated, How can I get the ajax response in Selenium?

using (var driver = new ChromeDriver())
        {
            driver.Navigate().GoToUrl(@"https://www.starbucks.com/card");
            driver.FindElement(By.Id("Card_Number")).SendKeys("7848549479363805");
            driver.FindElement(By.Id("Card_Pin")).SendKeys("91435723");
            driver.FindElement(By.XPath("//button[.='Check Balance']")).Click();
        }

由于上面的代码我无法阅读该回复?

How can I read this response as I am unable to with above code?

以下是Ajax请求后的响应:

<div id="cardBalanceWrapper">

<div id="card-balance-display" class=" region reset-left">
<img src="https://www.starbucks.com/images/cardimages/card_altdistcoreFY13_165.png" alt="Standard"></div>
    <div id="fetch_balance" class="region size1of3 reset">
    <strong>Card balance</strong>
<h2><span class="fetch_balance_value">$0.00</span></h2> <p>as of <span class="date">6/19/2017 6:56 PM</span></p></div>
<div class="fields region size1of1 reset-left">
<ul class="balance_links">

        <li><a href="/account/signin">Register This Card</a></li>

    <li><a href="/account/card/Reload">Reload This Card</a></li>
    <li><a href="/card/manage/history">View Card Transactions</a></li>
    <li><hr></li>
    <li><a href="/card?showdefault=False">Enter Another Card</a></li>
</ul>

推荐答案

要获取Ajax请求,您可以使用保持稳定
这是一种更快,更可靠的数据获取方式. 请勿将Selenium用于此类目的.

To fetch ajax requests you can use rest-assured
It is more fast and reliable way to get data. Do not use Selenium for such purposes.

这篇关于如何从Selenium中的Ajax请求获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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