我正在抓取他的网站。创建帐户的步骤。下面是url。
转到此站点后,单击"Dont have an account yet?",然后单击下一页上的"Agree"。
我有安全问题要回答。为此,我编写了以下脚本。
def findxpath_AddKey(xpath, key1, id, key2):
element = browser.find_element_by_xpath(xpath)
element.click()
browser.execute_script("arguments[0].setAttribute('aria-activedescendant',{})".format(key1),element)
span = browser.find_element_by_id(id)
browser.execute_script("arguments[0].innerText = {}".format(key2), span)
browser.execute_script("arguments[0].setAttribute('class',\"ui-selectmenu-button ui-button ui-widget ui-selectmenu-button-closed ui-corner-all\")",element)
findxpath_AddKey('//*[@id="selectSecurityQuestion1-button"]',"'ui-id-3'", 'selectSecurityQuestion1-button_text', "'Where is your favorite vacation spot?'")对于其他安全问题,重复上述过程,然后单击"continue"。但该网站抛出了错误,称这是为了回答安全问题。

发布于 2019-02-13 07:52:47
我不确定这是否能解决您的问题,但我知道,有时,手动编辑表单的内部文本不会注册为正在填写的表单-这就是我相信您使用setAttribute所做的事情。
尝试使用驱动程序的send_keys方法,而不是setAttribute。它看起来像这样:
form_field = browser.find_element_by_id('ID_OF_FORM_FIELD')
form_field.send_keys('Answer to security question')您也不必使用id来查找该字段。您可以使用find_element_by_xpath或您能想到的任何其他标识符。
https://stackoverflow.com/questions/54660372
复制相似问题