Javascript Python-selenium-AngularJS下拉列表,如何单击它们?
我正在浏览他的网站。创建一个帐户。下面是url 访问此网站后,单击Javascript Python-selenium-AngularJS下拉列表,如何单击它们?,javascript,python,angularjs,selenium-webdriver,drop-down-menu,Javascript,Python,Angularjs,Selenium Webdriver,Drop Down Menu,我正在浏览他的网站。创建一个帐户。下面是url 访问此网站后,单击“还没有帐户?”,然后单击下一页的“同意” 我有安全问题要回答。为此,我写了下面的脚本 def findxpath_AddKey(xpath, key1, id, key2): element = browser.find_element_by_xpath(xpath) element.click() browser.execute_script("arguments[0].setAttribute('a
“还没有帐户?”
,然后单击下一页的“同意”
我有安全问题要回答。为此,我写了下面的脚本
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?'")
对于其他安全问题,重复上述过程,然后单击“继续”。但该网站正在抛出错误,称这是为了填补安全问题
我不确定这是否能解决您的问题,但我知道,有时手动编辑表单的内部文本不会注册为正在填写的表单,我相信您正在使用
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\u element\u by\u xpath
或您能想到的任何其他标识符