Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
609 views
in Technique[技术] by (71.8m points)

javascript - TestCafe: console.log() the value of a selector

I try to select the text value SR-12948 of the span below with a TestCafe selector and then assign it to a const. So I can add it as a string to the withAttribute method. That doesn't really work. So I want to check what the value of my const srCaseIDString is. Is it possible to do that with a console log? So it logs the value of that const in the same terminal as my test results and errors appear?

This is my test:

<span data-template="" data-test-id="2014100715101007275150" class="supporting_text_il" style="">SR-12948</span>

import { Selector, t } from "testcafe";
import XPathSelector from "../utils/xpath-selector";

const button= Selector("#button");  

test("First Test", async (t) => {
     await t
        .click(button);

        const srCaseID = await  XPathSelector("//span[@data-test-id='2014100715101007275150']").innerText;

        console.log(srCaseID);

        const iframeCase = await Selector('iframe').withAttribute('title', srCaseIDString);
       
        await t
        .switchToIframe(iframeCase);
     
});

Thanks!

question from:https://stackoverflow.com/questions/65951633/testcafe-console-log-the-value-of-a-selector

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

innertext != innerText, it is case sensitive.

This works just fine:

const elementInnerText = await Selector('#id').innerText;
console.log(elementInnerText);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...