zoukankan      html  css  js  c++  java
  • Webdriver (python)中调用JS

      1、Webdriver 中调用JS,由于页面中的input是被隐藏起来的,所以必须用JS把隐藏的元素显示出来;

           browser.find_element_by_xpath("//div[@id='surveyItemsWrap']/div/div[2]/button[2]").click()
            time.sleep(5)
            inputs=browser.find_element_by_xpath("//body/input")
            js="var q=document.getElementByClassName('ts_bg alert');q.style.display='block';"
            #  setAttribute("style","display:block     
            print "js"
            browser.execute_script(js)
            browser.find_element_by_xpath("//body/input").send_keys('F:\Img2.jpg')
            print "ok"

    报错:

    Traceback (most recent call last):
      File "E:eclipsePythonCasesrcSurvey_testLogicMore.py", line 85, in test_Surveyor
        browser.execute_script(js)
      File "D:Python27libsite-packagesseleniumwebdriver
    emotewebdriver.py", line 396, in execute_script
        {'script': script, 'args':converted_args})['value']
      File "D:Python27libsite-packagesseleniumwebdriver
    emotewebdriver.py", line 164, in execute
        self.error_handler.check_response(response)
      File "D:Python27libsite-packagesseleniumwebdriver
    emoteerrorhandler.py", line 164, in check_response
        raise exception_class(message, screen, stacktrace)
    WebDriverException: Message: u"unknown error: Object #<HTMLDocument> has no method 'getElementByClassName'
      (Session info: chrome=28.0.1500.72)
      (Driver info: chromedriver=2.3,platform=Windows NT 6.1 SP1 x86_64)" 
    

    PS: JS有待加深学习!

  • 相关阅读:
    CodeForces 587A
    矩阵快速幂模板
    LCA模板
    Codeforces Round #226 (Div. 2 )
    Codeforces Round #225 (Div. 2)
    SGU132
    SRM 599 DIV 2
    POJ1038
    SGU223
    POJ1185
  • 原文地址:https://www.cnblogs.com/tyen0921/p/3524602.html
Copyright © 2011-2022 走看看