【问题标题】:Python - selenium - AngularJS drop downs, how to click them?Python - selenium - AngularJS 下拉菜单,如何点击它们?
【发布时间】:2019-02-12 23:41:06
【问题描述】:

我正在抓取他的网站。创建一个帐户。下面是网址

https://sjobs.brassring.com/TGnewUI/Search/Home/Home?partnerid=25222&siteid=5011&noback=1&fromSM=true#CreateAccount

进入本站后,点击"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"。但是该网站正在抛出错误,说是为了填写安全问题。

【问题讨论】:

    标签: javascript python angularjs selenium-webdriver drop-down-menu


    【解决方案1】:

    我不确定这是否能解决您的问题,但我确实知道,有时,手动编辑表单的内部文本不会注册为正在填写的表单——这就是我相信您使用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 或您能想到的任何其他标识符。

    【讨论】:

      猜你喜欢
      • 2016-11-12
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 2019-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多