How i can get text from web element and print in console (for example)

社会主义新天地 提交于 2019-12-10 17:47:53

问题


I have a problem with getting a text from elements on a web page. I'm using TestCafe e2e framework and want to print the contents of a text web element to console. Can you provide some code?

const getInnerText = ClientFunction(() => homePage.kzLink.innerText);
console.log(getInnerText());

what i get:

ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }

回答1:


To execute a client function, call it with the await keyword and a dependency.

const getInnerText = ClientFunction(() => homePage.kzLink.innerText, { 
    dependencies: { homePage.kzLink }
});

test('My Test', async t => {
    const text = await getInnerText();
    console.log(text);
});


来源:https://stackoverflow.com/questions/54415827/how-i-can-get-text-from-web-element-and-print-in-console-for-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!