![](/img/trans.png)
[英]How to extract the text 121.6 from the text node within the span tag using Selenium and Python
[英]How to extract the input text from angular form using Python Selenium?
我已经尝试过使用 .text 和 get_attribute('value') 从 angular 输入中获取值。
这是元素,
<input class="form-control m-input ng-pristine ng-valid ng-touched" name="contact" pattern="^((0091)|(\+91)|0?)[789]{1}\d{9}$" placeholder="Enter contact number" required="" type="text">
元素的截图,
此输入字段中有一个 email。 我想得到 ig something.mail.com。
这是我试过的代码,
contact = contact_field.get_property("value")
contact = contact_field.get_attribute("value")
contact = contact_field.text
根据 HTML:
<input class="form-control m-input ng-pristine ng-valid ng-touched" name="contact" pattern="^((0091)|(\+91)|0?)[789]{1}\d{9}$" placeholder="Enter contact number" required="" type="text">
在将文本发送到<input>
元素时,没有任何属性可以满足 HTML DOM中的值更改。
如果<input>
元素包含以下属性和 ev.net, DOM 树中的更改就会发生:
<input>
、 <select>
和<textarea>
元素触发change
事件。 与<input>
事件不同,change 事件不一定会在每次更改元素值时触发。 例子:
例子#a:
<input type="text" class="form-control" (input)="onSearchChange($event.target.value)">
例子#b:
<input type="text" [ngModel]="mymodel" (ngModelChange)="valuechange($event)" />
例子#c:
<input type="text" [ngModel]="mymodel" (keypress)="mymodel=$event.target.value"/>
例子#d:
<textarea [(ngModel)]="smsMessage" (change)="changeSMSMessage()"></textarea>
注意:HTML 规范列出了应该触发更改事件的<input>
类型。
例如,对于某些元素,包括<input type="text">
,更改事件不会在控件失去焦点之前触发。 在下面的字段中输入内容,然后单击其他地方以触发事件。
HTML:
<input placeholder="Enter some text" name="name"/>
<p id="log"></p>
JavaScript:
const input = document.querySelector('input');
const log = document.getElementById('log');
input.addEventListener('change', updateValue);
function updateValue(e) {
log.textContent = e.target.value;
}
您可以在以下位置找到一些相关的详细讨论:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.