我有20行长文本和HTML代码,需要在表单测试中使用。对于小文本,我可以使用类似以下的内容:
browser.actions().mouseMove(element(by.id("field_bodytext")).sendKeys("BodyText <h2>Protractor</h2> Text1")).perform();
,它将正常工作。但是,对于20行,则不是。我已经在Protractor API页面中看到了此信息,但是在我的情况下看不到如何使用它:
http://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.sendKeys
var form = driver.findElement(By.css('form'));
var element = form.findElement(By.css('input[type=file]'));
element.sendKeys('/path/to/file.txt');
form.submit();
有一个硒示例,我看不出如何适应:Selenium Webdriver enter multiline text in form without submitting it
这是Angular中的表单字段:
<div class="form-group"><a href="https://wordhtml.com/" target="_blank">Wordhtml.com</a>
<label class="form-control-label" jhiTranslate="jhipsterpressApp.post.bodytext" for="field_bodytext">Bodytext</label>
<textarea type="text" rows="10" cols="50" class="form-control" name="bodytext" id="field_bodytext"
[(ngModel)]="post.bodytext" required minlength="2" maxlength="65000">
<div [hidden]="!(editForm.controls.bodytext?.dirty && editForm.controls.bodytext?.invalid)">
<small class="form-text text-danger"
[hidden]="!editForm.controls.bodytext?.errors?.required" jhiTranslate="entity.validation.required">
This field is required.
</small>
<small class="form-text text-danger"
[hidden]="!editForm.controls.bodytext?.errors?.minlength" jhiTranslate="entity.validation.minlength" translateValues="{ min: 2 }">
This field is required to be at least 2 characters.
</small>
<small class="form-text text-danger"
[hidden]="!editForm.controls.bodytext?.errors?.maxlength" jhiTranslate="entity.validation.maxlength" translateValues="{ max: 65000 }">
This field cannot be longer than 65000 characters.
</small>
</div>
</textarea>
</div>
要插入的文本可能是这样的:
<h2>What is JHipsterPress?</h2>
<ul>
<li>It is an open source and collaborative project made with Jhipster.</li>
<li>It is a live project that it is explained in its GitHub project. Explained? What do you mean? Whether you are a beginner that wants to find out an example about how to <a href="https://github.com/Tonterias/JhipsterPress08/blob/master/ReadMe/Solution1.md" target="_blank"> How to open access to the REST Api:</a> or a more advance user who wants to see <a href=" https://github.com/Tonterias/JhipsterPress08/blob/master/ReadMe/Solution20.md" target="_blank"> How to change DTOs to load attributes of not related entities:</a> and see the actual code working, just visit the <a href="https://github.com/Tonterias/JhipsterPress08" target="_blank"> ReadMe file at GITHUB</a></li>
<li>And YES, you can use it for your own website.</li>
<li>At the same time JHipsterPress will try to create a community for Jhipster developers to join groups about different topics such as Websockets, Mapstruct, or anything you like.</li>
</ul>
<br />
答案 0 :(得分:0)
按照@ lunin-roman的说法将HTML放在引号中``,然后将其命名为:
let htmltext = `<h2>What is JHipsterPress?</h2> and so on`;
element(by.id("field_bodytext")).sendKeys(htmltext);
,然后在element.sendKeys
中使用它