Selenium+python+shell+crontab+firefox

Source: Internet
Author: User
Tags python script

Recently in a script to try an automatic punch, found a few questions, hereby recorded.

Environment:

Ubuntu 12.04.4 LTS

Selenium 2.43.0

Firefox 32.0.3

1 Originally the machine Selenium,firefox are installed, but Firefox updates from time to time, so selenium may not support the current version of Firefox.

Update Selenium command:

sudo pip install-u Selenium

2 python script used:

1 #!/usr/bin/env python2 3 ImportSYS4  fromSeleniumImportWebdriver5 6URL ="http://XXX.com/"7Driver =Webdriver. Firefox ()8 9Driver.get (url+"/")TenDriver.find_element_by_xpath ("//div[2]/input"). Send_keys ("XXX") OneDriver.find_element_by_xpath ("//div[3]/input"). Send_keys ("XXX") ADRIVER.FIND_ELEMENT_BY_ID ("Loginbutton"). Click () -Driver.find_element_by_css_selector ("a > IMG"). Click () -  theDriver.quit ()

3 Crontab Automatic task-related commands:

Crontab-l: Displays the current user's scheduled tasks

CRONTAB-E: Editing the current user's scheduled tasks

The actual command used:

0 * * 1-5 export display=:0.0 && python/home/yzzw006/wifi/yzzw_doc/kq.py

Here are two points to note:

1 because the task must be opened in the foreground browser, it must be added "export display=:0.0";

2 script address executed in crontab use absolute path as far as possible

Selenium+python+shell+crontab+firefox

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.