{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "private_outputs": true, "provenance": [], "history_visible": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "source": [ "Install python packages through Pip" ], "metadata": { "id": "ZnmqS_1x8EqJ" } }, { "cell_type": "code", "source": [ "!pip install selenium webdriver-manager requests idna chardet certifi unitest" ], "metadata": { "id": "rg-47f1L4wX7" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "SETUP THE GUI OR HEADLESS BROWSER CHROME INSTANCE" ], "metadata": { "id": "SVTu6r-274V5" } }, { "cell_type": "code", "source": [], "metadata": { "id": "-Rlms3Si253d" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Z7G0lEK94qMv" }, "outputs": [], "source": [ "import unittest\n", "from selenium import webdriver\n", "from selenium.webdriver.common.keys import Keys\n", "from selenium.webdriver.chrome.options import Options\n", "\n", "class PythonOrgSearch(unittest.TestCase):\n", "\n", " def setUp(self):\n", " # chrome_options = Options()\n", " # chrome_options.add_argument("--no-sandbox")\n", " # chrome_options.add_argument("--headless")\n", " self.driver = webdriver.Chrome(options=chrome_options)\n", "\n" ] }, { "cell_type": "markdown", "source": [ "Scroll towards the bottom of page (SLOW)" ], "metadata": { "id": "-bDMHqrc7zB-" } }, { "cell_type": "code", "source": [ "def scroll(self, keyword, add_url=""):\n", " # self.browser.get("https://www.pf.com.pk/search?q={}&source=lnms&tbm=isch{}\".format(keyword, add_url))\n", " self.browser.get("https://www.pf.com.pk\".format(keyword, add_url))\n", "\n", " time.sleep(1)\n", "\n", " print('Scrolling down')\n", "\n", " elem = self.browser.find_element(By.TAG_NAME, "header")\n", "\n", " last_scroll = 0\n", " scroll_patience = 0\n", " NUM_MAX_SCROLL_PATIENCE = 50\n", "\n", " while True:\n", " elem.send_keys(Keys.PAGE_DOWN)\n", " time.sleep(0.2)\n", "\n", " scroll = self.get_scroll()\n", " if scroll == last_scroll:\n", " scroll_patience += 1\n", " else:\n", " scroll_patience = 0\n", " last_scroll = scroll\n", "\n", " if scroll_patience >= NUM_MAX_SCROLL_PATIENCE:\n", " break" ], "metadata": { "id": "7g6JZQcJ7xg2" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "Page title assertion" ], "metadata": { "id": "iH5DR6QV7xNy" } }, { "cell_type": "code", "source": [ "def assert_title(self):\n", " driver = self.driver\n", " driver.get("https://www.pf.com.pk\")\n", " elem = driver.find_element(By.CLASS_NAME, "home-logo").title\n", " self.assertIn("Programmers Force ", driver.title)\n", " elem.send_keys("pycon")\n", " elem.send_keys(Keys.RETURN)\n", " assert "No results found." not in driver.page_source\n", "\n", "\n", "\n" ], "metadata": { "id": "ogZczwEA6N_b" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "Logo Assertion" ], "metadata": { "id": "5EY0KOhL8eQ5" } }, { "cell_type": "code", "source": [ "def assert_logo(self):\n", " driver = self.driver\n", " driver.get("https://www.pf.com.pk\")\n", " self.assertIn("Programmers Force ", driver.title)\n", " self.assertIn("Programmer Force",driver .title)\n", " elem = driver.find_element(By.NAME, "Logo").get_attribute('class')\n", " self.assertIn("homelogo",elem)\n", " # elem.send_keys(Keys.RETURN)\n", " assert "No results found." in driver.page_source\n", "\n", "# print "Button 1: ", driver.find_element(By.NAME, "btnK").get_attribute("value")\n", "# print "Button 2: ", driver.find_element(By.NAME, "btnI").get_attribute("value")\n", "# print "Img: ", driver.find_element(By.TAG_NAME, "img").get_attribute("src")\n", "# print "Label: ", driver.find_element(By.LINK_TEXT, "Gmail").text\n", "\n", "# # driver.find_element(By.NAME, "btnK").click()\n", "# driver.find_element(By.CLASS_NAME, "lsb").click()\n", "# driver.find_element(By.LINK_TEXT, "ABC Home Page - ABC.com").click()\n", "\n", " # def tearDown(self):\n", " # #self.driver.quit()\n", " # pass\n", "\n", " # if name == "main":\n", " # unittest.main(verbosity=2)\n", "# # driver.find_element(By.PARTIAL_LINK_TEXT, "ABC Home Page").click()" ], "metadata": { "id": "zZ_MTpN16TzR" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "Navigation and screenshots" ], "metadata": { "id": "I2TsxA028mto" } }, { "cell_type": "code", "source": [ "def navigate_header(self)\n", " driver = self.driver\n", " driver.get("https://www.pf.com.pk\")\n", " driver.find_element(By.LINK_TEXT, "Careers").click()\n", " driver.find_element(By.LINK_TEXT, "About Us").click()\n", " driver.find_element(By.LINK_TEXT, "Careers").click()\n", " driver.find_element(By.LINK_TEXT, "Open Positions").click()\n", " driver.find_element(By.CSS_SELECTOR, ".job-inner-blocks:nth-child(2) > .job-box-container:nth-child(5) .apply-m-now").click()\n", " driver.find_element(By.CSS_SELECTOR, ".single-apply-now").click()\n" ], "metadata": { "id": "x8GawNe48pP8" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "Submitt the form" ], "metadata": { "id": "xPrrlWNa9q8B" } }, { "cell_type": "code", "source": [ "# Generated by Selenium IDE\n", "import pytest\n", "import time\n", "import json\n", "from selenium.webdriver.common.by import By\n", "from selenium.webdriver.common.action_chains import ActionChains\n", "from selenium.webdriver.support import expected_conditions\n", "from selenium.webdriver.support.wait import WebDriverWait\n", "from selenium.webdriver.common.keys import Keys\n", "from selenium.webdriver.common.desired_capabilities import DesiredCapabilities\n", "from selenium.driver import driver\n", "\n", "def submitForm(self):\n", " driver.get("https://pf.com.pk\")\n", " # driver.get("https://pf.com.pk/\")\n", " # driver.find_element(By.LINK_TEXT, "About Us").click()\n", " # driver.find_element(By.LINK_TEXT, "Careers").click()\n", " driver.find_element(By.LINK_TEXT, "Open Positions").click()\n", " driver.find_element(By.CSS_SELECTOR, ".job-inner-blocks:nth-child(2) > .job-box-container:nth-child(5) .apply-m-now").click()\n", " driver.find_element(By.CSS_SELECTOR, ".single-apply-now").click()\n", " driver.find_element(By.ID, "name").click()\n", " driver.find_element(By.ID, "name").click()\n", " element = driver.find_element(By.ID, "name")\n", " actions = ActionChains(driver)\n", " actions.double_click(element).perform()\n", " driver.find_element(By.ID, "name").click()\n", " driver.find_element(By.ID, "name").click()\n", " element = driver.find_element(By.ID, "name")\n", " actions = ActionChains(driver)\n", " actions.double_click(element).perform()\n", " driver.find_element(By.ID, "name").click()\n", " driver.find_element(By.ID, "name").send_keys("Sample")\n", " driver.find_element(By.ID, "email").send_keys("sample@test.com")\n", " driver.find_element(By.ID, "university").click()\n", " driver.find_element(By.ID, "university").send_keys("Universoty of Engineerin g")\n", " driver.find_element(By.ID, "cgpa_cd").click()\n", " driver.find_element(By.ID, "cgpa_cd").send_keys("4.2")\n", " driver.find_element(By.CSS_SELECTOR, "#cur-working > .first .wpcf7-list-item-label").click()\n", " driver.find_element(By.ID, "salry-expt").click()\n", " driver.find_element(By.ID, "salry-expt").send_keys("50")\n", " driver.find_element(By.CSS_SELECTOR, ".apply-now-form").click()\n", " driver.find_element(By.ID, "curent-salry").click()\n", " driver.find_element(By.ID, "curent-salry").send_keys("10")\n", " driver.find_element(By.ID, "doj").click()\n", " driver.find_element(By.ID, "doj").send_keys("2024-05-31")\n", " driver.find_element(By.ID, "hear-abt-us").click()\n", " driver.find_element(By.ID, "hear-abt-us").send_keys("Lahore")\n", " driver.find_element(By.ID, "experiance").click()\n", " dropdown = driver.find_element(By.ID, "experiance")\n", " dropdown.find_element(By.XPATH, "//option[. = 'More than 7 Years']").click()\n", " driver.find_element(By.CSS_SELECTOR, ".apply-now-form").click()\n", " driver.find_element(By.ID, "city").click()\n", " driver.find_element(By.ID, "city").send_keys("Dera Gugti")\n", " driver.find_element(By.ID, "address").click()\n", " driver.find_element(By.ID, "address").send_keys("Jamali")\n", " driver.find_element(By.ID, "phone").click()\n", " driver.find_element(By.ID, "phone").send_keys("001222555884")\n", " driver.find_element(By.ID, "cnic").click()\n", " driver.find_element(By.ID, "cnic").send_keys("352222585100")\n", " driver.find_element(By.ID, "email").click()\n", " driver.find_element(By.ID, "name").click()\n", " driver.find_element(By.ID, "email").click()\n", " driver.find_element(By.ID, "email").click()\n", " element = driver.find_element(By.ID, "email")\n", " actions = ActionChains(driver)\n", " actions.double_click(element).perform()\n", " driver.find_element(By.ID, "email").click()\n", " driver.find_element(By.ID, "email").click()\n", " driver.find_element(By.ID, "email").send_keys("kabhi@aoo.na")\n", " driver.find_element(By.ID, "name").click()\n", " driver.find_element(By.ID, "name").send_keys("Sample Man")\n", " driver.find_element(By.ID, "dob").click()\n", " driver.find_element(By.ID, "dob").send_keys("2016-02-01")\n", " driver.find_element(By.CSS_SELECTOR, "li:nth-child(5) > p:nth-child(1)").click()\n", " driver.find_element(By.ID, "resume").click()\n", " driver.find_element(By.ID, "resume").send_keys("C:\\fakepath\\SQA_Assessment_Tasks (1).pdf")\n", " driver.find_element(By.CSS_SELECTOR, ".apply-now-form li:nth-child(21)").click()\n", " driver.find_element(By.ID, "submit-btn").click()\n", " element = driver.find_element(By.ID, "submit-btn")\n", " actions = ActionChains(driver)\n", " actions.move_to_element(element).perform()\n", " element = driver.find_element(By.CSS_SELECTOR, "body")\n", " actions = ActionChains(driver)\n", " actions.move_to_element(element, 0, 0).perform()\n", " driver.find_element(By.ID, "cnic").click()\n", " driver.find_element(By.ID, "cnic").send_keys("3522225851002")\n", " driver.find_element(By.ID, "submit-btn").click()\n", " driver.find_element(By.LINK_TEXT, "Expertise").click()\n", "\n" ], "metadata": { "id": "NzqTvlNo9A1m" }, "execution_count": null, "outputs": [] } ] }