我试图在带有Appium的UI Simulator上的webview中单击“下一步”。但是,单击后,由于某些原因会清除该字段中的所有其他值
我尝试使用appium TouchAction,但它们不适用于Webview。也尝试使用JavaScript执行,但是'document.getElementByXpath'并没有真正起作用,所以我决定尝试使用Selenium / Appium
def test_entering_details(self):
# Select gender, enter month/day/year
self.if_click('//*[@id="donor-followup-0"]/div/div/div[1]/div[2]/div/div/span/label[2]')
self.if_enter('//*[@id="monthInput"]', '10')
self.if_enter('//*[@id="dayInput"]', '10')
self.if_enter('//*[@id="yearInput"]', '1981')
self.clickNext()
def clickNext(self):
self.if_click('//*[@id="next-button"]')
def if_click(self, element_xpath):
try:
self.check_element_present(element_xpath)
element = WebDriverWait(self.wd, 20).until(ec.element_to_be_clickable((By.XPATH, element_xpath)))
print(element)
self.move_to_element(element)
element.click() #This clears all the other text fields in the form
return True
except Exception:
print('Error clicking on %s' % element_xpath)
raise
我希望单击“下一步”时它会移至下一页,但是它清除了月/日/年的值,并由于必须输入而抛出错误
HTML有点难看,因为它是Grommet react应用
<div class="grommetux-box grommetux-box--direction-column grommetux-box--align-self-center grommetux-box--responsive grommetux-box--pad-none grommetux-box--margin-horizontal-large grommetux-box--width-xxlarge grommetux-box--size" role="main">
<form role="form" class="mainForm" id="donor-followup-0">
<div class="onefield">
<div class="qAndBtns">
<div>
<div class="date_field test">
<div style="text-align: left;"><label class="grommetux-label grommetux-label--margin-small grommetux-label--medium">Birth Date</label>
<div class="grommetux-form-field grommetux-form-field--size-medium grommetux-form-field--error" aria-labelledby="dialog_prolog__node" aria-live="assertive"><span class="grommetux-form-field__error">Invalid Date Format</span><span
class="grommetux-form-field__contents">
<div class="dateHolster">
<div class="dateInput"><label class="grommetux-label grommetux-label--margin-medium grommetux-label--medium" for="monthInput">Month</label><input type="number" autocomplete="off" name="month" id="monthInput" min="1" max="12"
class="grommetux-text-input grommetux-input" placeholder="MM" value=""></div>
<div class="dateInput"><label class="grommetux-label grommetux-label--margin-medium grommetux-label--medium" for="dayInput">Day</label><input type="number" autocomplete="off" name="day" id="dayInput" min="1" max="31"
class="grommetux-text-input grommetux-input" placeholder="DD" value=""></div>
<div class="dateInput"><label class="grommetux-label grommetux-label--margin-medium grommetux-label--medium" for="yearInput">Year</label><input type="number" autocomplete="off" name="year" id="yearInput" min="1900"
max="9999" class="grommetux-text-input grommetux-input" placeholder="YYYY" value=""></div>
</div>
</span></div>
</div>
</div>
<div class="radio_field test">
<div class="radio-button-group" role="radiogroup" aria-labelledby="dialog_prolog radioLabel" style="display: table; margin: 0px auto; width: 100%;">
<div class="grommetux-form-field grommetux-form-field--size-medium" name="entryGender" value="Male" aria-live="assertive"><span class="grommetux-form-field__contents"><label id="radioLabel" tabindex="0"
class="grommetux-label grommetux-label--margin-small grommetux-label--medium">Your Gender:</label><label for="Male" class="grommetux-radio-button"><input name="entryGender" id="Male" class="grommetux-radio-button__input"
type="radio" value="Male"><span class="grommetux-radio-button__control"></span><span class="grommetux-radio-button__label">Male</span></label><label for="Female" class="grommetux-radio-button"><input name="entryGender"
id="Female" class="grommetux-radio-button__input" type="radio" value="Female"><span class="grommetux-radio-button__control"></span><span class="grommetux-radio-button__label">Female</span></label></span></div>
</div>
</div>
</div>
<div id="nav-button-group" class="questionBtnWrapper"><button aria-describedby="dialog_prolog entry_prolog" id="next-button" type="submit" class="grommetux-button grommetux-button--primary grommetux-button--plain"
aria-label="Next Question">Next</button></div>
</div>
</div>
</form>
</div>