简体   繁体   中英

How to Get InnerText using Coypu and C#?

I have the following HTML:

<h1 _ngcontent-ng-cli-universal-c8="" class="title" id="greetingsLabel1"> Welkom, <span _ngcontent-ng-cli-universal-c8=""></span></h1>

I'm using coypu to find the elements, when I do:

browser.FindId(GreetingsLabel1Path).InnerHTML

I get:

Welkom, <span _ngcontent-ng-cli-universal-c8=""></span>

but I really just want Welkom, . I tried to use InnerText instead of Inner HTML but it doesn't work with InnerText, it gives the message "ElementScope does not contain a definition for InnetText and no accessible extension method 'InnerText' accepting a first argument of type ElementScope could not be found(are you missing a using directive or an assembly reference?)".

Is there any way to get just Welkom, using coypu?

Since the span tag is nested in the h1, and thus part of the innerhtml, you would have to remove that part by manipulating the string yourself. The most robust way would probably be to remove everything after the first space.

var innerhtmlString = browser.FindId(GreetingsLabel1Path).InnerHTML;
var welcometext = innerhtmlString.Split()[0];

now you can use the var welcometext in your test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM