<legend id='tzW49'><style id='tzW49'><dir id='tzW49'><q id='tzW49'></q></dir></style></legend>

      <small id='tzW49'></small><noframes id='tzW49'>

      <i id='tzW49'><tr id='tzW49'><dt id='tzW49'><q id='tzW49'><span id='tzW49'><b id='tzW49'><form id='tzW49'><ins id='tzW49'></ins><ul id='tzW49'></ul><sub id='tzW49'></sub></form><legend id='tzW49'></legend><bdo id='tzW49'><pre id='tzW49'><center id='tzW49'></center></pre></bdo></b><th id='tzW49'></th></span></q></dt></tr></i><div id='tzW49'><tfoot id='tzW49'></tfoot><dl id='tzW49'><fieldset id='tzW49'></fieldset></dl></div>

      • <bdo id='tzW49'></bdo><ul id='tzW49'></ul>
      1. <tfoot id='tzW49'></tfoot>

        Testcafe 从元素中获取文本

        时间:2023-09-06

          • <bdo id='9miS4'></bdo><ul id='9miS4'></ul>

            • <small id='9miS4'></small><noframes id='9miS4'>

              <tfoot id='9miS4'></tfoot>
                <tbody id='9miS4'></tbody>

                <i id='9miS4'><tr id='9miS4'><dt id='9miS4'><q id='9miS4'><span id='9miS4'><b id='9miS4'><form id='9miS4'><ins id='9miS4'></ins><ul id='9miS4'></ul><sub id='9miS4'></sub></form><legend id='9miS4'></legend><bdo id='9miS4'><pre id='9miS4'><center id='9miS4'></center></pre></bdo></b><th id='9miS4'></th></span></q></dt></tr></i><div id='9miS4'><tfoot id='9miS4'></tfoot><dl id='9miS4'><fieldset id='9miS4'></fieldset></dl></div>

                  <legend id='9miS4'><style id='9miS4'><dir id='9miS4'><q id='9miS4'></q></dir></style></legend>
                  本文介绍了Testcafe 从元素中获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试从 Chrome 上的模式中获取文本.使用控制台,我可以得到如下内部文本:

                  I'm trying to get a text from a modal on Chrome. Using the console, I can get the inner text as follows:

                  document.querySelector('.my-form > a').innerText
                  // returns http://a-url.com
                  

                  现在,在我的测试中,我可以使用评估元素

                  Now, on my test, I can evaluate the element using

                  const myText = Selector('.my-form > a').innerText;
                  await t
                    .expect(myText).contains('url');
                  

                  我什至可以点击那个网址

                  and I can even click on that URL

                  await t.click(myText);
                  

                  但例如,我不能将该内部文本放入变量中.我尝试使用 这篇文章

                  but I cannot put that inner text to a variable, for instance. I tried using a ClientFunction from this post

                  const getUrl = ClientFunction(() => document.querySelector('.my-form > a').innerText);
                  
                  test('My Test', async t => {
                  const text = await getUrl();
                  console.log(text);
                  });
                  
                  // this results in 
                  // TypeError: Cannot read property 'innerText' of null
                  

                  并尝试使用普通选择器作为 这篇文章建议

                  and tried using a plain Selector as this post suggests

                  const text = Selector('.my-form > a').innerText;
                  const inner = await text.textContent;
                  console.log(inner);
                  
                  // prints: undefined
                  

                  如何从元素中提取文本?我知道 t.selectText 在这种情况下是有限的,对吧?

                  How to extract a text from an element? I understand that t.selectText is limited in this scenario, right?

                  推荐答案

                  来自 文档 你想要的:

                  const text = await Selector('.my-form > a').innerText;

                  这篇关于Testcafe 从元素中获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:将 Jest 与 Puppeteer 一起使用:评估失败:ReferenceErr 下一篇:检查其中一个 div 是否包含我在守夜人中的值

                  相关文章

                  最新文章

                1. <i id='kVPOr'><tr id='kVPOr'><dt id='kVPOr'><q id='kVPOr'><span id='kVPOr'><b id='kVPOr'><form id='kVPOr'><ins id='kVPOr'></ins><ul id='kVPOr'></ul><sub id='kVPOr'></sub></form><legend id='kVPOr'></legend><bdo id='kVPOr'><pre id='kVPOr'><center id='kVPOr'></center></pre></bdo></b><th id='kVPOr'></th></span></q></dt></tr></i><div id='kVPOr'><tfoot id='kVPOr'></tfoot><dl id='kVPOr'><fieldset id='kVPOr'></fieldset></dl></div>

                  <small id='kVPOr'></small><noframes id='kVPOr'>

                  <tfoot id='kVPOr'></tfoot>

                      <legend id='kVPOr'><style id='kVPOr'><dir id='kVPOr'><q id='kVPOr'></q></dir></style></legend>

                      • <bdo id='kVPOr'></bdo><ul id='kVPOr'></ul>