Thursday, November 14, 2019

Finding elements with Python Selenium

HTML:
<button type="submit" class="button search-button" onclick="">Search</button>

Using XPATH:
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, '//button[@type="submit" and @class="button search-button" and text()="Search"]'))).click()
Using CSS_SELECTOR:
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button[type="submit"][class="button search-button"]'))).click()

Sunday, November 10, 2019

How to convert your Python script into an executable file (from .py to .exe)

1. pip install pyinstaller
2. Go to the folder which contains your python script (.py)... e.g. C:\user\Tim\
3. pyinstaller.exe --onefile --icon=sun_icon.ico python_script.py --noconsole

  • icon (*.ico) file should be in the same folder as your python script
  • --noconsole will eliminate the black screen that appears on running the exe file
  • "--hidden-import=modulename" will ensure that python also includes modules (that tend to be hidden) into the exe file (not guaranteed to work)
  • "-v" for verbose/detailed log

4. Go into the "dist" subfolder i.e. C:\user\Tim\dist\
5. Run the .exe file
Note: If the file appears to be stuck in a black screen, ensure any related images are also copied to the "dist" folder where the .exe file is located.

Tuesday, November 5, 2019

How to Install an Older Version of Python

1. Go to https://www.python.org/downloads/

2. Open every link (for that Python's version you are interested in) in a different tab. For example, if you are looking to install Python 3.6, then open the link that to Python 3.6.9, Python 3.6.8, etc. Start with the latest version (Python 3.6.9) and move backwards, because the latest version will have the latest security updates.

3. Within each tab, look for the executable installer that fits your requirements. This is an .exe file that will run easily once you download it to your PC. Pick the file that meets your PC requirements. For example, if your operating system uses Windows 64 bit, then download "Windows x86-64 executable installer"

4. Double click the downloaded executable file (e.g. python-3.6.8-amd64.exe) to install it on your PC.

5. Start your favorite IDE e.g. PyCharm

6. Create a new project and ensure you specify the absolute path for your project interpreter. Example:

  • Project Interpreter: Base interpreter: C:\Users\Tim\AppData\Local\Programs\Python\Python36\python.exe
  • Hit the Create button, and you're ready to go


Popular Posts