<script>/** This is a WORKAROUND to allow React <input> to be scriptable
* from Appium in iOS.
*/document.addEventListener('blur',evt=>{// we are only interested in <input>sif(evt.target.tagName!=='INPUT'&&evt.target.tagName!=='TEXTAREA'){return;}// whenever a "blur" event is fired,// we will simulate an onChange event in React// fire "change" event in React 15 and beforeconstevent=newEvent('change',{bubbles:true});event.simulated=true;// simulate change event in React 16constinput=evt.target;constlastValue=input.value+'HACK';// this forces last value to be different than the current value, and forces the change event to fireconsttracker=input._valueTracker;tracker&&tracker.setValue(lastValue);input.dispatchEvent(event);},true);</script>
这样可以解决 sendKeys 没有更新 react component state 的情况,但是毕竟注入了多余 Script,如果有更好的方法欢迎留言评论。