【发布时间】:2017-03-28 20:02:32
【问题描述】:
我正在设置网络驱动程序以从我在工作中使用的几个网站上抓取报告数字。所有这些都受密码保护,直到现在还没有问题。这是我尝试与之交互的登录屏幕:
我在 Firefox 中使用 Selenium webdriver 和 Python 3.6。
在这个网站上,webdriver 需要输入用户名,然后在密码输入和提交按钮可见之前与“下一步”按钮交互。我可以填写用户名,但到目前为止还无法让网络驱动程序与“下一步”按钮进行交互。
以下是来自该站点的按钮 html 的 sn-p:
<a class="x-btn attached-btn blue x-unselectable x-box-item x-btn-attached-btn-small x-item-disabled x-btn-disabled" style="height: 40px; right: auto; left: 282px; top: 0px; margin: 0px;" hidefocus="on" unselectable="on" role="button" aria-hidden="false" aria-disabled="true" id="button-1021" data-componentid="button-1021">
<span id="button-1021-btnWrap" data-ref="btnWrap" role="presentation" unselectable="on" style="" class="x-btn-wrap x-btn-wrap-attached-btn-small ">
<span id="button-1021-btnEl" data-ref="btnEl" role="presentation" unselectable="on" style="height:auto;" class="x-btn-button x-btn-button-attached-btn-small x-btn-text x-btn-button-center ">
<span id="button-1021-btnIconEl" data-ref="btnIconEl" role="presentation" unselectable="on" class="x-btn-icon-el x-btn-icon-el-attached-btn-small " style=""></span>
<span id="button-1021-btnInnerEl" data-ref="btnInnerEl" unselectable="on" class="x-btn-inner x-btn-inner-attached-btn-small">next</span>
</span>
</span>
</a>
我尝试过使用类名、id 和 css 选择器,但到目前为止还没有成功。下面是python sn-p:
def exe(self):
browser = webdriver.Firefox()
wait = WebDriverWait(browser, 15)
yesterday = date.today() - timedelta(1)
browser.get("https://ssp.vertamedia.com")
try:
userElement = wait.until(EC.visibility_of_element_located((By.ID,'textfield-1020-inputEl')))
userElement.send_keys(self.cred.pop('User'))
browser.find_element_by_id('button-1021').click()
passElement = wait.until(EC.visibility_of_element_located((By.ID, 'textfield-1027-inputEl')))
passElement.send_keys(self.cred.pop('Password'))
browser.find_element_by_id('button-1028').click()
except TimeoutException:
self.cred['Impression'] = "Login error"
self.cred['Revenue'] = "Login error"
self.cred['Date'] = yesterday.strftime('%m%d%y')
基本上当它点击我输入密码的 passElement 部分时,它会遇到“元素不可见”错误。
任何关于如何让它与下一个按钮交互的建议将不胜感激!
【问题讨论】:
-
设置用户名后有没有试过多睡一会儿?