我正在从网站获取数据,每当我单击链接以获取电话号码时,都会打开一个模态表单以首先询问我的电话号码,然后向我显示电话号码。
我现在面临的挑战是,我想将键发送到输入字段,所以因为输入字段没有名称或 ID,我使用 xpath 找到了输入字段:
xxx = driver.find_element_by_xpath("//input[@placeholder='081xxxxxxxx']")
我打印了这个,它返回了一些硒对象,但是当我尝试发送如下键时:
xxx.send_keys('08100000000')
下面是一段 html 代码:
<div class="row">
<div class="medium-12 columns">
<div class="guest-text">
One step closer! <br />
<span>Please provide your contact number to view business contact details</span>
</div>
<form action="" data-abide="ajax" novalidate="novalidate">
<div id="txtUserPhoneNumber" ng-show="!isLoggedIn && collectUserPhone == ''" class="guest-no">
<label>
<div class="guest-label">Phone Number</div>
<input type="text" placeholder="081xxxxxxxx" ng-model="UserPhoneNew" required data-invalid="" aria-invalid="true" maxlength="11">
</label>
</div>
</form>
</div>
我试过了:
xxx = driver.find_element_by_xpath("//input[@placeholder='081xxxxxxxx']")
xxx.send_keys('08100000000')
dummy_number = driver.find_element_by_xpath("//div[contains(@class, 'modal small guest')]/div[contains(@class, 'guest-modal-wrapper')]//form[1]//input[1]")
dummy_number.send_keys('081000000')
我收到错误消息:
Traceback (most recent call last):
File "Dropbox/automation/vconnect.py", line 76, in <module>
RunAutomation.instantiatechrome()
File "Dropbox/automation/vconnect.py", line 61, in instantiatechrome
xxx.send_keys('081xxxxxxxx')
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 479, in send_keys
'value': keys_to_typing(value)})
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
(Session info: chrome=66.0.3359.139)
(Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.13.0-39-generic x86_64)
欢迎您的意见。