Python

时间:2017-02-10 23:18:49

标签: python selenium

亲爱的Python社区,

我使用Selenium在Python 3上做了一个小小的脚本,以在线自动完成一些基本任务。它工作正常。它打开了firefox浏览器,在网上登录,在搜索字段上键入文本等等。没什么太花哨的。

我仍然在学习和尝试不同的东西,所以在此期间我安装了anaconda,python 2.7,并将更新的python 3形式3.4(我认为)安装到3.6。我搞砸了所有这些。

现在我的剧本不再有用了......

首先它抱怨没有找到geckodriver。我相信我第一次没有安装。无论如何,我下载并把它放在Path环境变量上。

脚本然后运行,但之前没有停止过。它不会等待页面加载。如果我不想让它失败,我必须在selenium上使用显式/隐式等待。

我在使用browser.find_element_by_partial_link_text在网上查找元素时遇到问题,当我编写脚本时效果很好。

def download(serial,apoc_user,apoc_pass):
    shutil.rmtree(aux.download_path, ignore_errors=True)


    profile = webdriver.FirefoxProfile()
    profile.set_preference('browser.download.folderList', 2) # custom location
    profile.set_preference('browser.download.manager.showWhenStarting', False)
    profile.set_preference('browser.download.dir', aux.absolut_path + aux.download_path)
    profile.set_preference('browser.helperApps.neverAsk.saveToDisk', aux.all_types_of_files)

    browser = webdriver.Firefox(firefox_profile=profile)

    browser.get("https://some.web.com")

    elem = browser.find_element_by_id('username')
    elem.send_keys(user)
    passElem = browser.find_element_by_id('password')
    passElem.send_keys(password)
    browser.find_element_by_id('loginBtn').click()

    elem = browser.find_element_by_id('Asset')
    elem.send_keys(serial)
    elem.submit()

在修改我的代码之前,有人知道现在发生了什么吗? 我目前有python 3.6和selenium 3.0.0。我尝试使用python 3.5和selenium 3.0.2但没有成功。 我使用在Windows 7上运行的Pycharm Community Edition进行编码。

欢迎任何帮助! 谢谢大家。

0 个答案:

没有答案