diff --git a/README.md b/README.md index f26fc54..0bd32da 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,6 @@ [![forthebadge](http://forthebadge.com/images/badges/built-by-developers.svg)](http://forthebadge.com) [![forthebadge](http://forthebadge.com/images/badges/check-it-out.svg)](http://www.logan1x.me/Python-Scripts/) - -[![Join the chat at https://gitter.im/Python_Scripts/Lobby](https://badges.gitter.im/Python_Scripts/Lobby.svg)](https://gitter.im/Python_Scripts/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - > This Repo is a collection of Various python scripts. In this repo there are different kinds of python scripts for their respective uses. These all are open sourced and you can use them in any form for free. @@ -399,7 +396,7 @@ Distributed under the MIT LICENSE license. See [``LICENSE``](https://github.com/ The following people helped in creating the above content. -![ayrusme](./images/ayrusme.png "ayrusme" )![lionasp](./images/lionasp.png "lionasp" )![zinuzoid](./images/zinuzoid.png "zinuzoid" )![dgupta777](./images/dgupta777.png "dgupta777" )![chiraag-jain](./images/chiraag-jain.png "chiraag-jain" )![niharikakrishnan](./images/niharikakrishnan.png "niharikakrishnan" )![ahadali](./images/ahadali.png "ahadali" )![khushboopaddiyar](./images/khushboopaddiyar.png "khushboopaddiyar" )![Harshvardhan58](./images/Harshvardhan58.png "Harshvardhan58" )![pr0me](./images/pr0me.png "pr0me" )![abhinavralhan](./images/abhinavralhan.png "abhinavralhan" )![Souldiv](./images/Souldiv.png "Souldiv" )![szepnapot](./images/szepnapot.png "szepnapot" )![SuryaThiru](./images/SuryaThiru.png "SuryaThiru" )![apuayush](./images/apuayush.png "apuayush" )![ishank011](./images/ishank011.png "ishank011" )![ValentinChCloud](./images/ValentinChCloud.png "ValentinChCloud" )![MadhavBahlMD](./images/MadhavBahlMD.png "MadhavBahlMD" )![vigov5](./images/vigov5.png "vigov5" )![RodolfoFerro](./images/RodolfoFerro.png "RodolfoFerro" )![toonarmycaptain](./images/toonarmycaptain.png "toonarmycaptain" )![harsha7890](./images/harsha7890.png "harsha7890" )![Pradhvan](./images/Pradhvan.png "Pradhvan" )![Rafi993](./images/Rafi993.png "Rafi993" )![ehnydeel](./images/ehnydeel.png "ehnydeel" )![shivamp123](./images/shivamp123.png "shivamp123" )![vis2797](./images/vis2797.png "vis2797" )![Sharanpai](./images/Sharanpai.png "Sharanpai" )![kalbhor](./images/kalbhor.png "kalbhor" )![iyanuashiri](./images/iyanuashiri.png "iyanuashiri" )![akshitgrover](./images/akshitgrover.png "akshitgrover" )![KayvanMazaheri](./images/KayvanMazaheri.png "KayvanMazaheri" )![Logan1x](./images/Logan1x.png "Logan1x" ) +![ayrusme](./images/ayrusme.png "ayrusme" )![lionasp](./images/lionasp.png "lionasp" )![zinuzoid](./images/zinuzoid.png "zinuzoid" )![dgupta777](./images/dgupta777.png "dgupta777" )![chiraag-jain](./images/chiraag-jain.png "chiraag-jain" )![niharikakrishnan](./images/niharikakrishnan.png "niharikakrishnan" )![ahadali](./images/ahadali.png "ahadali" )![khushboopaddiyar](./images/khushboopaddiyar.png "khushboopaddiyar" )![Harshvardhan58](./images/Harshvardhan58.png "Harshvardhan58" )![pr0me](./images/pr0me.png "pr0me" )![abhinavralhan](./images/abhinavralhan.png "abhinavralhan" )![Souldiv](./images/Souldiv.png "Souldiv" )![szepnapot](./images/szepnapot.png "szepnapot" )![SuryaThiru](./images/SuryaThiru.png "SuryaThiru" )![apuayush](./images/apuayush.png "apuayush" )![ishank011](./images/ishank011.png "ishank011" )![ValentinChCloud](./images/ValentinChCloud.png "ValentinChCloud" )![MadhavBahlMD](./images/MadhavBahlMD.png "MadhavBahlMD" )![vigov5](./images/vigov5.png "vigov5" )![RodolfoFerro](./images/RodolfoFerro.png "RodolfoFerro" )![toonarmycaptain](./images/toonarmycaptain.png "toonarmycaptain" )![harsha7890](./images/harsha7890.png "harsha7890" )![Pradhvan](./images/Pradhvan.png "Pradhvan" )![Rafi993](./images/Rafi993.png "Rafi993" )![ehnydeel](./images/ehnydeel.png "ehnydeel" )![shivamp123](./images/shivamp123.png "shivamp123" )![vis2797](./images/vis2797.png "vis2797" )![Sharanpai](./images/Sharanpai.png "Sharanpai" )![kalbhor](./images/kalbhor.png "kalbhor" )![iyanuashiri](./images/iyanuashiri.png "iyanuashiri" )![akshitgrover](./images/akshitgrover.png "akshitgrover" )![KayvanMazaheri](./images/KayvanMazaheri.png "KayvanMazaheri" )![Logan1x](./images/Logan1x.png "Logan1x" )![mohitpeshwani](./images/mohitpeshwani.png "mohitpeshwani" ) ### If you like the project give a star [Star button](https://github.com/Logan1x/Python-Scripts/stargazers) diff --git a/bin/File_Dispatcher/main.py b/bin/File_Dispatcher/main.py new file mode 100644 index 0000000..2e8b711 --- /dev/null +++ b/bin/File_Dispatcher/main.py @@ -0,0 +1,18 @@ +import shutil +import os + +path = "D:\\Abdul Rehman\\AI Automations\\File_Dispatcher" + +print("Before Moving Files ") +print(os.listdir(path)) + +m = "D:\\Abdul Rehman\\AI Automations\\Source\\Source\\abd.txt" +print(os.listdir(m)) + +destination = "D:\\Abdul Rehman\\Downloads_Backup\Images" + +if m.endswith(('.txt')): + + dest = shutil.move(source, destination, copy_function="Move") +else: + print("Unable to Fetch it") diff --git a/bin/Linux and Windows Desktop Setup Automation/README.md b/bin/Linux and Windows Desktop Setup Automation/README.md new file mode 100644 index 0000000..493202a --- /dev/null +++ b/bin/Linux and Windows Desktop Setup Automation/README.md @@ -0,0 +1,65 @@ +# 🛠️ In Development + +This repository contains a collection of **automation and optimization scripts**, aiming to improve the **development environment on Linux** and **gaming performance on Windows**. + +--- + +## 🐧 Linux Automation Scripts + +The Python script **`automation_script.py`** is designed to streamline the setup of a new development environment on Linux. +It automates the installation of essential tools, ensuring everything is ready to get you started quickly. + +### Linux Script Features +- **System Updates**: Runs `apt update` and `apt upgrade` to keep packages up to date. +- **Essential Tools**: Automatically installs `htop` (process monitor), `Git` (version control), and `Neofetch` (system information). +- **Development Environment**: Installs **Visual Studio Code** via Snap. +- **Customization**: Includes `GNOME Tweaks` and `GNOME Shell Extensions` to customize the user interface. + +--- + +## 🎮 Windows Optimization Scripts + +The PowerShell script **`windows_gaming_tweaks.ps1`** is an interactive tool for optimizing Windows and boosting gaming performance. +It provides a simple, straightforward menu to run system maintenance and repair tasks. + +### 💻 Windows Script Features +- **SFC/SCANNOW**: Scans and repairs corrupted system files. +- **CHKDSK**: Analyzes and fixes disk errors to maintain data integrity. +- **Temporary File Cleanup**: Removes unnecessary files that take up space and slow down the system. +- **DISM**: Repairs the operating system image, ensuring updates work properly. + +--- + +## How to Use + +### 🔹 On Linux +1. Clone the repository: + ```bash + git clone https://github.com/Logan1x/Python-Scripts.gitgit + ``` + +2. Enter the repository directory: + ```bash + cd Python-Scripts + ``` + +3. Execute the script: + ```bash + python3 automation_script.py + ``` + +### 🔹 On Windows + +1. Open PowerShell as Administrator. To do this, right-click the Start Menu icon and select `Windows PowerShell (Admin)` or `Terminal (Admin)`. + +2. Navigate to the directory where the script is saved: + ```bash + cd C:\path\to\repository + ``` + +3. Execute the script: + ```bash + .\windows_gaming_tweaks.ps1 + ``` + +Note: If the script doesn't run, you might need to adjust the PowerShell execution policy. Use the command `Set-ExecutionPolicy RemoteSigned` (run as Administrator) to allow local scripts to execute. \ No newline at end of file diff --git a/bin/Linux and Windows Desktop Setup Automation/scriptLinux.py b/bin/Linux and Windows Desktop Setup Automation/scriptLinux.py new file mode 100644 index 0000000..c20380d --- /dev/null +++ b/bin/Linux and Windows Desktop Setup Automation/scriptLinux.py @@ -0,0 +1,38 @@ +#In development + +import subprocess +import sys + +def autom_sudoapt(command): + try: + subprocess.run(command, check=True, text=True, shell=True) + print(f"Comando '{command}' executado com sucesso.") + except subprocess.CalledProcessError as e: + print(f"Erro ao executar o comando '{command}': {e}", file=sys.stderr) + sys.exit(1) + +def main(): + print("Iniciando a atualização e instalação do htop, vscode e git...") + + autom_sudoapt("sudo apt update -y") + + autom_sudoapt("sudo apt upgrade -y") + + autom_sudoapt("sudo apt install -y htop") + + autom_sudoapt("sudo apt install -y git") + + autom_sudoapt("sudo snap install -y --classic code") + + autom_sudoapt("sudo apt install neofetch -y") + + autom_sudoapt("sudo apt install gnome-tweaks -y") + + autom_sudoapt("sudo apt install gnome-shell-extensions -y") + + autom_sudoapt("sudo apt install gnome-terminal -y") + + print("Atualização e instalação concluídos!") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/bin/Linux and Windows Desktop Setup Automation/scriptWin.ps1 b/bin/Linux and Windows Desktop Setup Automation/scriptWin.ps1 new file mode 100644 index 0000000..60184b9 --- /dev/null +++ b/bin/Linux and Windows Desktop Setup Automation/scriptWin.ps1 @@ -0,0 +1,104 @@ +#In development + +# Check for administrator privileges +if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { + Write-Warning "This script needs to be run as an Administrator. Restarting with elevated privileges..." + Start-Process powershell "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs + exit +} + +# Function to display the menu +function Show-Menu { + Clear-Host + Write-Host "------------------------------------------------------" -ForegroundColor Cyan + Write-Host "Script for Windows optimization with a focus on games " -ForegroundColor White + write-Host " Developed by euopaulin " -ForegroundColor White + Write-Host "------------------------------------------------------" -ForegroundColor Cyan + Write-Host " Choose an option:" -ForegroundColor White + Write-Host "------------------------------------------------------" -ForegroundColor Cyan + Write-Host "1. Run SFC/SCANNOW" -ForegroundColor DarkRed + Write-Host "2. Run CHKDSK" -ForegroundColor DarkRed + Write-Host "3. Clean temporary files" -ForegroundColor DarkRed + Write-Host "4. Restore system image (DISM)" -ForegroundColor DarkRed + Write-Host "5. Exit" -ForegroundColor DarkGreen + Write-Host "------------------------------------------------------" -ForegroundColor Cyan +} + +# Main loop to show the menu and process user input +while ($true) { + Show-Menu + + $choice = Read-Host "Enter the number of your choice" + + switch ($choice) { + "1" { + Write-Host "Option 1 selected: Running SFC/SCANNOW..." -ForegroundColor Yellow + try { + & sfc /scannow + if ($LASTEXITCODE -eq 0) { + Write-Host "SFC/SCANNOW executed successfully." -ForegroundColor Green + } else { + Write-Host "Error running SFC/SCANNOW. Make sure to run the script as an Administrator." -ForegroundColor Red + } + } catch { + Write-Host "An error occurred while running the command." -ForegroundColor Red + } + break + } + "2" { + Write-Host "Option 2 selected: Running CHKDSK..." -ForegroundColor Yellow + $drive = Read-Host "Enter the drive letter (e.g., C)" + Write-Host "Checking drive $drive..." -ForegroundColor Yellow + try { + # Using the native PowerShell command + Repair-Volume -DriveLetter $drive -Scan -Verbose + Write-Host "CHKDSK executed successfully." -ForegroundColor Green + } catch { + Write-Host "An error occurred while running the command." -ForegroundColor Red + } + break + } + "3" { + Write-Host "Option 3 selected: Cleaning temporary files..." -ForegroundColor Yellow + try { + $tempPaths = "$env:TEMP\*", "$env:SystemRoot\Temp\*" + foreach ($tempPath in $tempPaths) { + if (Test-Path $tempPath) { + Remove-Item -Path $tempPath -Recurse -Force -ErrorAction SilentlyContinue + } + } + Write-Host "Temporary files cleaned successfully." -ForegroundColor Green + } catch { + Write-Host "An error occurred while cleaning temporary files." -ForegroundColor Red + } + break + } + "4" { + Write-Host "Option 4 selected: Restoring system image (DISM)..." -ForegroundColor Yellow + try { + & dism /Online /Cleanup-Image /RestoreHealth + if ($LASTEXITCODE -eq 0) { + Write-Host "DISM executed successfully." -ForegroundColor Green + } else { + Write-Host "Error running DISM. Make sure to run the script as an Administrator." -ForegroundColor Red + } + } catch { + Write-Host "An error occurred while running the command." -ForegroundColor Red + } + break + } + "5" { + Write-Host "Exiting the script. Goodbye!" -ForegroundColor Red + Start-Sleep -Seconds 2 + exit + } + default { + Write-Host "Invalid option. Please enter a number from 1 to 5." -ForegroundColor Red + break + } + } + + Write-Host "" + Write-Host "Press any key to continue..." -ForegroundColor White + $null = [System.Console]::ReadKey($true) +} \ No newline at end of file diff --git a/bin/Selenium basics with python/README.md b/bin/Selenium basics with python/README.md new file mode 100644 index 0000000..b098245 --- /dev/null +++ b/bin/Selenium basics with python/README.md @@ -0,0 +1,134 @@ +## Selenium Driver with the Python from scratch with examples + +## Need to install +Python
+Selenium ------------------> pip instll selenium
+Chromedriver--------------->https://chromedriver.chromium.org/getting-started
+
+ +
+ +## Selenium basics 1 + (i) basics of the selenium web driver small commands
+ (ii) minimize and maximise the functionality
+ +
+ +## Selenium basics 2 +Navigation commands mainly use to move previous page(<-) and forward page(->) page +(i) driver.back()
+(ii) driver.forward()
+ +
+ +## Selenium basics 3 +Demonstrating the condtional function is_selected, is_enabled, is_displayed() mainly for validation purpose
+ (i) is_enabled()
+ (ii) is_selected()
+ (iii) is_displayed()
+ +
+ +## Selenium basics 4 + +Demonstrating the Waits in selenium web driver
+ +Explicit Wait command, the WebDriver is directed to wait until a certain condition occurs before proceeding with executing the code. +Setting Explicit Wait is important in cases where there are certain elements that naturally take more time to load +
+Implicit Wait directs the Selenium WebDriver to wait for a certain measure of time before throwing an exception. +Once this time is set, WebDriver will wait for the element before the exception occurs +
+ +
+ +## Selenium basics 5 +Input Box And Text Box fucntionality using selenium driver
+ +(i) send_keys() to add the message or input into input_box/textarea
+(ii) submit button to submit.
+ + +
+ +## Selenium basics 6 +In this web page we will select the checkbox and radio types of input +using
+ element.click()
+And also check whenever there is a iframe we need to go into iframe using (optional)(Note: we are selecting radio buttons in frame that's why required to go iframe)
+ (i)switch_to.frame('frame_id') --> to select the elements in the specific sections
+ (ii)switch_to.default_content() --> switch to normal mode always is best practice
+ (This two are mostly used in the automation testing perspective. "In safty place like the tracsaction for ex, slack transcation they use nested iframes.)
+ +
+ +## Selenium basics 7 +Lets select from the drop down plane with the help of the selenium web driver command by 3 ways as follow:
+Step 1) Select the element using the element = select(driver.find_element())
+Step 2) Select the value using the following three ways we have
+ (i)element.select_by_visible_text("")
+ (ii)element.select_by_value("")
+ (iii)element.select_by_index()
+
+ +## Selenium basics 8 +''' +We are trying to interact with the links and mainly simply we can get them using the By function
+ +Let's getting the No of the links, all link text, partial link text so we get hands on find_elements function too.
+ + +another ways to find +(i) By.LINK_TEXT --> complete text for single element
+(ii) By.PARTIAL_LINK_TEXT --> partial text is enough for finding individual work
+''' + +
+ +## Selenium basics 9 + +Let us check how we can handle the alerts and popups on the website using selenium websdrive in python +
+we can driver.switch_to.alert()
+where multiple things there accept using .accept()
+where multiple things there accept using .dismiss() +
+another ways to find
+(i) By.LINK_TEXT --> complete text for single element
+(ii) By.PARTIAL_LINK_TEXT --> partial text is enough for finding individual work +'''
+
+ +## Selenium basics 10 +Handling the Windows tab using selenium webdriver with Python
+ +Basics which is necessary to understand.
+ +
+ +## Selenium basics 11 + +handle the scroll in a web page using the python with selenium
+ +
+ +## Selenium basics 12 + +handle the mouse hower or touch on mobile screen actions through the selenium web driver commands
+ + +## Selenium basics 13 + +Double Click action using mouse handling on python selenium
+ +## Selenium basics 14 + +perform some more functionality around ActionChain
+ + +

Connect with me:

+

+mohit peshwani +coding_nightmare +mohit peshwani +

diff --git a/bin/Selenium basics with python/basics_selenium1.py b/bin/Selenium basics with python/basics_selenium1.py new file mode 100644 index 0000000..7a7d4c8 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium1.py @@ -0,0 +1,12 @@ + +''' +Simple hands on the selenium with help of python library + +''' +from selenium import webdriver +driver = webdriver.Chrome(executable_path="chromedriver.exe") # to use the functionality of the web driver we need to create the object of the drive with specific browser which we want to use +driver.get("https://mohitpeshwani.github.io/crazyprogrammer/") #to load the target url we user webdriver.get("url") to load it +driver.maximize_window() #to maxiumize the windows +driver.minimize_window() #to minimize the windows +print(driver.title) #to get the exact title of the page we can use the webdriver.title +driver.quit() # to close the automation windows \ No newline at end of file diff --git a/bin/Selenium basics with python/basics_selenium10.py b/bin/Selenium basics with python/basics_selenium10.py new file mode 100644 index 0000000..bf633ab --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium10.py @@ -0,0 +1,40 @@ +''' +Handling the Windows tab using selenium webdriver with Python + +Basics which is necessary to understand + +Every windows has it's own hexadecimal value assign with it ex,(CDwindow-5907D74FC9E6C6E2918AB140D08C34AE) +using + driver.current_window_handler + +To switch into within any other tab of the similar webpage we can simply use the same + + driver.switch_to.windows(handler) + +to get all the windows + + driver.window_handles + +Remeber difference between the two .quit() and .close() + --> quit() terminate the browser + --> close() terminate the current tab on the browser + +''' +from selenium import webdriver +from selenium.webdriver.common.by import By +import time +driver =webdriver.Chrome(executable_path="chromeDriver.exe") +driver.get("https://demo.automationtesting.in/Windows.html") +clicked_element = driver.find_element(By.XPATH,"//a[@href='http://www.selenium.dev']//button[@class='btn btn-info'][normalize-space()='click']").click() +time.sleep(2) +print(driver.current_window_handle) +tabs = driver.window_handles +for tab in tabs: + driver.switch_to.window(tab) + time.sleep(2) + print(driver.title) + driver.close() +driver.quit() + + + diff --git a/bin/Selenium basics with python/basics_selenium11.py b/bin/Selenium basics with python/basics_selenium11.py new file mode 100644 index 0000000..083e427 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium11.py @@ -0,0 +1,21 @@ +''' +Let's check who we can handle the scroll in a web page using the python with selenium + +Simplest wait is to execute the js using the + driver.execute_script("windows.scrollBy(0,500)) + + Note: we can execute javascript using + (1) driver.execute_script("","") + (2) driver.execute_async_scipt("","") + + +''' + +from selenium import webdriver +import time +driver =webdriver.Chrome(executable_path="chromeDriver.exe") +driver.get("https://mohitpeshwani.github.io/crazyprogrammer/") +time.sleep(3) +driver.execute_script("window.scrollBy(0,500)","") +time.sleep(3) +driver.quit() diff --git a/bin/Selenium basics with python/basics_selenium12.py b/bin/Selenium basics with python/basics_selenium12.py new file mode 100644 index 0000000..777bcd7 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium12.py @@ -0,0 +1,31 @@ +''' +Let'us handle the mouse hower or touch on mobile screen actions through the selenium web driver commands + +step 1: We need to import addition Object which is + ActionChain +step 2: + Also initilize it using using a variable is always preferable + action =ActionChain(webdriver) + +step 3: + to perform any action we need to + element.move_to().perform() + +''' + +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver import ActionChains +import time +driver =webdriver.Chrome(executable_path="chromeDriver.exe") +driver.get("https://www.browserstack.com") +action = ActionChains(driver) +time.sleep(3) +product_menu = driver.find_element(By.CSS_SELECTOR,"#product-menu-toggle") +live_submenu = driver.find_element(By.CSS_SELECTOR,"a[aria-label='Live'] div[class='dropdown-link-text']") +action.move_to_element(product_menu).perform() +time.sleep(2) +live_submenu.click() +time.sleep(2) +print("Title include Live: ",driver.title) +driver.quit() \ No newline at end of file diff --git a/bin/Selenium basics with python/basics_selenium13.py b/bin/Selenium basics with python/basics_selenium13.py new file mode 100644 index 0000000..95e3170 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium13.py @@ -0,0 +1,32 @@ +''' +Let us check the Double Click action using mouse handling on python selenium + +step 1: We need to import addition Object which is + ActionChain +step 2: + Also initilize it using using a variable is always preferable + action =ActionChain(webdriver) + +step 3: + to perform any Doubleclick + action.doule_click(element).perform() ------------> Double click action + action.context_click(element).perform() ------------> Right click actions appear + +''' + +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver import ActionChains +import time + +driver=webdriver.Chrome(executable_path="chromedriver.exe") +driver.get("https://testautomationpractice.blogspot.com/") +element = driver.find_element(By.CSS_SELECTOR,"button[ondblclick='myFunction1()']") +time.sleep(2) +#ActionChains(driver).double_click(element).perform() +ActionChains(driver).context_click(element).perform() + +time.sleep(2) +label2 = driver.find_element(By.ID,"field2") +print(label2.get_property) +driver.quit() diff --git a/bin/Selenium basics with python/basics_selenium14.py b/bin/Selenium basics with python/basics_selenium14.py new file mode 100644 index 0000000..681f358 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium14.py @@ -0,0 +1,26 @@ +''' +Let us perform some more functionality around ActionChain + + Drag and Drop --> we can simple drag and drop the elements using + action.drag_and_drop(element_source, element_target).perform() + + + +''' +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver import ActionChains +import time + +driver=webdriver.Chrome(executable_path="chromedriver.exe") +driver.get("https://testautomationpractice.blogspot.com/") +element = driver.find_element(By.CSS_SELECTOR,"button[ondblclick='myFunction1()']") +time.sleep(2) +action =ActionChains(driver) +drag = driver.find_element(By.ID,"draggable") +to_drop = driver.find_element(By.ID,"droppable") +action.drag_and_drop(drag,to_drop).perform() +time.sleep(2) +driver.maximize_window() +driver.save_screenshot("dragAnddrop.png") +driver.quit() diff --git a/bin/Selenium basics with python/basics_selenium15.py b/bin/Selenium basics with python/basics_selenium15.py new file mode 100644 index 0000000..2d5ea85 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium15.py @@ -0,0 +1,31 @@ +''' +When performing API testing we manily work on the cookies and determine +So simple things around the cookies are demonstrate which are manily used by QA/Developer during building the website + +(i) driver.get_cookies() ----------------------------------------------------> Get all the cookies properities +(ii) driver.get_cookie("name") -----------------------------------------------> Get individual cookies +(iii) driver.add_cookie({"name":"string_value", "value": "string_value"})------> Injecting the cookies in current driver from coding point of view +(iv) driver.delete_all_cookies() ---------------------------------------------> Deleting all the cookies +(v) driver.delete_cookie(name)-----------------------------------------------> Deleting individual cookie + +''' + + + +from selenium import webdriver +from selenium.webdriver.common.by import By +import time +driver =webdriver.Chrome(executable_path="chromeDriver.exe") +driver.get("https://www.linkedin.com/in/mohit-peshwani/") +cookies = driver.get_cookies() +# get all the cookies +# print(cookies) --------------------> print all the cookies with list not looks good uncomment it for better understanding while performing +driver.add_cookie({"name":"python","value":"mohit"}) + +for cookie in cookies: + print(cookie) +time.sleep(2) + +cookies = driver.delete_all_cookies() +print(driver.get_cookies()) +driver.quit() diff --git a/bin/Selenium basics with python/basics_selenium2.py b/bin/Selenium basics with python/basics_selenium2.py new file mode 100644 index 0000000..0e889c3 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium2.py @@ -0,0 +1,22 @@ +''' +Navigation commands mainly use to move previous page(<-) and forward page(->) page +(i) driver.back() +(ii) driver.forward() + +''' + +from selenium import webdriver +import time +driver =webdriver.Chrome(executable_path="chromedriver.exe") +driver.get("https://www.github.com") +print(driver.title) +time.sleep(2) # to wait for 2 seconds +driver.get("https://www.google.com") +print(driver.title) +time.sleep(2) +driver.back() # it goes once action backward +time.sleep(2) +print("Navigated to the back page: ",driver.title) +driver.forward() # it goes to the next action page if gone +print("Navigrated to the next page: ",driver.title) +driver.quit() diff --git a/bin/Selenium basics with python/basics_selenium3.py b/bin/Selenium basics with python/basics_selenium3.py new file mode 100644 index 0000000..95e476b --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium3.py @@ -0,0 +1,26 @@ +''' +conditional commands are used to check wheater the fuction is working fine or not properly (Validation purpose) +(i) is_enable() +(ii) is_displayed() +(iii) is_selected() + +prior this we need to select the selector to check for the element to use +using css selector and xpath selector +''' +from selenium import webdriver +from selenium.webdriver.common.by import By # need to use this selector +driver = webdriver.Chrome(executable_path="chromedriver.exe") + + +''' +Using the CSS_selector we are selecting input and checking wheather it's dispalyed properly or not +Executed : 1)is_displayed() 2)is_enabled() + +''' +driver.get("https://www.google.com/") + +element = driver.find_element(By.CSS_SELECTOR,"input[title='Search']") + +print(element.is_displayed()) +print(element.is_enabled()) + diff --git a/bin/Selenium basics with python/basics_selenium3_is_selected.py b/bin/Selenium basics with python/basics_selenium3_is_selected.py new file mode 100644 index 0000000..7d4a1b2 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium3_is_selected.py @@ -0,0 +1,15 @@ +''' +Demonstrating the condtional function is_selected in this file +''' + +from selenium import webdriver +from selenium.webdriver.common.by import By +driver = webdriver.Chrome(executable_path="chromedriver.exe") +driver.get("https://demoqa.com/radio-button") + +# storing elements and detect wheather they are selected or not + +selected_button = driver.find_element(By.CSS_SELECTOR,"label[for='yesRadio']") +selected_button2 = driver.find_element(By.CSS_SELECTOR,"label[for='impressiveRadio']") +print(selected_button.is_selected()) +driver.quit() diff --git a/bin/Selenium basics with python/basics_selenium4_explict_wait.py b/bin/Selenium basics with python/basics_selenium4_explict_wait.py new file mode 100644 index 0000000..564f369 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium4_explict_wait.py @@ -0,0 +1,23 @@ +''' +Explicit Wait command, the WebDriver is directed to wait until a certain condition occurs before proceeding with executing the code. +Setting Explicit Wait is important in cases where there are certain elements that naturally take more time to load + +Implicit Wait directs the Selenium WebDriver to wait for a certain measure of time before throwing an exception. +Once this time is set, WebDriver will wait for the element before the exception occurs +''' +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC + +driver = webdriver.Chrome(executable_path="chromedriver.exe") +driver.get("https://mohitpeshwani.github.io/crazyprogrammer/") +try: + # wait 10 extra seconds before looking for element until it found my website image + element = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.CSS_SELECTOR, "img[src='./images/man12.png']")) + ) + print(element.is_displayed()) # should return true + print("Demontrating the explicit wait ") +finally: + driver.quit() \ No newline at end of file diff --git a/bin/Selenium basics with python/basics_selenium4_implict_wait.py b/bin/Selenium basics with python/basics_selenium4_implict_wait.py new file mode 100644 index 0000000..45a0294 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium4_implict_wait.py @@ -0,0 +1,20 @@ +''' +Explicit Wait command, the WebDriver is directed to wait until a certain condition occurs before proceeding with executing the code. +Setting Explicit Wait is important in cases where there are certain elements that naturally take more time to load + +Implicit Wait directs the Selenium WebDriver to wait for a certain measure of time before throwing an exception. +Once this time is set, WebDriver will wait for the element before the exception occurs +''' +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC + +driver = webdriver.Chrome(executable_path="chromedriver.exe") +driver.get("https://mohitpeshwani.github.io/crazyprogrammer/") +#implicity waiting for the 10 seconds +driver.implicitly_wait(10) +#element will check after the 10 seconds of wait +element=driver.find_element(By.XPATH,"//div[@class=' hero flex flex-1 items-center justify-between ']//img[1]") #using xpath selector to get the element +print(element.is_displayed()) +driver.quit() diff --git a/bin/Selenium basics with python/basics_selenium5.py b/bin/Selenium basics with python/basics_selenium5.py new file mode 100644 index 0000000..5a21173 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium5.py @@ -0,0 +1,25 @@ +''' +Input Box And Text Box fucntionality using selenium driver + +(i) send_keys() to add the message or input into input_box/textarea +(ii) submit button to submit. +''' +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +import time +driver = webdriver.Chrome(executable_path="chromedriver.exe") +driver.get('https://app.hackthebox.com/login') +driver.maximize_window() +time.sleep(5) +# adding the id/class of input boxs into the variables +login_email = driver.find_element(By.XPATH,"//input[@id='loginEmail']") +password = driver.find_element(By.XPATH,"//input[@id='loginPassword']") +submit_btn = driver.find_element(By.XPATH,"//input[@id='loginPassword']") + +# Now we will send the random names, email and message and submit +login_email.send_keys("automation@gmail.com") +password.send_keys("Ronaldo the GOAT") +submit_btn.submit() +time.sleep(5) +driver.quit() \ No newline at end of file diff --git a/bin/Selenium basics with python/basics_selenium6.py b/bin/Selenium basics with python/basics_selenium6.py new file mode 100644 index 0000000..5c3b303 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium6.py @@ -0,0 +1,38 @@ +''' +In this web page we will select the checkbox and radio types of input +using + element.click() +And also check whenever there is a iframe we need to go into iframe using (optional)(Note: we are selecting radio buttons in frame that's why required to go iframe) + (i)switch_to.frame('frame_id') --> to select the elements in the specific sections + (ii)switch_to.default_content() --> switch to normal mode always is best practice + (This two are mostly used in the automation testing perspective. "In safty place like the tracsaction for ex, slack transcation they use nested iframes.) + + +''' + +from selenium import webdriver +from selenium.webdriver.common.by import By +driver = webdriver.Chrome(executable_path="chromedriver.exe") +driver.get("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_radio") + +#Switching to iframe with id you can even use iframe_name +driver.switch_to.frame('iframeResult') + +#getting the locators of the elements +html_selector = driver.find_element(By.XPATH, "//input[@id='html']") +css_selector = driver.find_element(By.XPATH, "//input[@id='css']") +js_selector = driver.find_element(By.XPATH, "//input[@id='javascript']") + +#Selected the element +html_selector.click() + +# html selector should give the true and other will be false +print(html_selector.is_selected()) +print(css_selector.is_selected()) +print(js_selector.is_selected()) + +#Switching to normal window format +driver.switch_to.default_content() +driver.quit() + + diff --git a/bin/Selenium basics with python/basics_selenium7.py b/bin/Selenium basics with python/basics_selenium7.py new file mode 100644 index 0000000..93df509 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium7.py @@ -0,0 +1,29 @@ +''' +Lets select from the drop down plane with the help of the selenium web driver command by 3 ways as follow: +Step 1) Select the element using the element = select(driver.find_element()) +Step 2) Select the value using the following three ways we have + (i)element.select_by_visible_text("") + (ii)element.select_by_value("") + (iii)element.select_by_index() +''' + +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import Select +import time +driver = webdriver.Chrome(executable_path="chromeDriver.exe") + +driver.get("https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407") +link_first = Select(driver.find_element(By.ID,'RESULT_RadioButton-9')) + +#link_first.select_by_visible_text("Afternoon") + +#link_first.select_by_value("Radio-2") + +link_first.select_by_index(2) + +time.sleep(2) + +driver.quit() + + diff --git a/bin/Selenium basics with python/basics_selenium8.py b/bin/Selenium basics with python/basics_selenium8.py new file mode 100644 index 0000000..d1998f3 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium8.py @@ -0,0 +1,37 @@ +''' +We are trying to interact with the links and mainly simply we can get them using the By function + +Let's getting the No of the links, all link text, partial link text so we get hands on find_elements function too. + + +another ways to find +(i) By.LINK_TEXT --> complete text for single element +(ii) By.PARTIAL_LINK_TEXT --> partial text is enough for finding individual work +''' +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + +driver =webdriver.Chrome(executable_path="chromeDriver.exe") +driver.get("https://mohitpeshwani.github.io/crazyprogrammer/") +time.sleep(5) +no_of_links = driver.find_elements(By.TAG_NAME,'a') +time.sleep(2) +print("No of the links available in the web page:", len(no_of_links)) + +#we link to go on the link no 2 +no_of_links[2].click() + +#printing the assosicate text with the link +for i in no_of_links: + print(i.text) + +#element using LINK_TEXT +print(driver.find_element(By.LINK_TEXT,'mohitpesh23@gmail.com').is_displayed()) + +#element using LINK_TEXT +print(driver.find_element(By.PARTIAL_LINK_TEXT,'mohitpesh23').is_displayed()) + +time.sleep(5) +driver.quit() + diff --git a/bin/Selenium basics with python/basics_selenium9.py b/bin/Selenium basics with python/basics_selenium9.py new file mode 100644 index 0000000..e8bcc71 --- /dev/null +++ b/bin/Selenium basics with python/basics_selenium9.py @@ -0,0 +1,28 @@ +''' +Let us check how we can handle the alerts and popups on the website using selenium websdrive in python + +we can driver.switch_to.alert() +where multiple things there accept using .accept() +where multiple things there accept using .dismiss() + +''' + +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +import time + +driver = webdriver.Chrome(executable_path= "chromeDriver.exe") +driver.get("https://demo.automationtesting.in/Alerts.html") +alert_box = driver.find_element(By.CSS_SELECTOR,".btn.btn-danger") +alert_box.click() +time.sleep(2) +# Switching to the ok using accept() else we can use the dismiss() for cancle purpose if available +driver.switch_to.alert.accept() +time.sleep(2) +driver.switch_to.default_content() + +time.sleep(2) +driver.quit() + + diff --git a/bin/Selenium basics with python/chromedriver.exe b/bin/Selenium basics with python/chromedriver.exe new file mode 100644 index 0000000..bc6efd7 Binary files /dev/null and b/bin/Selenium basics with python/chromedriver.exe differ diff --git a/bin/Selenium basics with python/dragAnddrop.png b/bin/Selenium basics with python/dragAnddrop.png new file mode 100644 index 0000000..cf7e54a Binary files /dev/null and b/bin/Selenium basics with python/dragAnddrop.png differ diff --git a/bin/Wallpaper Changer requirements.txt b/bin/Wallpaper Changer requirements.txt index 53438f1..9b79631 100644 --- a/bin/Wallpaper Changer requirements.txt +++ b/bin/Wallpaper Changer requirements.txt @@ -1,5 +1,5 @@ praw==7.1.0 -requests==2.22.0 +requests==2.20.0 config==0.5.0.post0 schedule==0.6.0 mmh3==2.5.1 diff --git a/bin/highcharts_loader_requirements.txt b/bin/highcharts_loader_requirements.txt index ba29c76..3cb65d1 100644 --- a/bin/highcharts_loader_requirements.txt +++ b/bin/highcharts_loader_requirements.txt @@ -1 +1 @@ -requests==2.8.14 \ No newline at end of file +requests==2.20.0 \ No newline at end of file diff --git a/images/mohitpeshwani.png b/images/mohitpeshwani.png new file mode 100644 index 0000000..addccba Binary files /dev/null and b/images/mohitpeshwani.png differ