-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload.py
More file actions
48 lines (38 loc) · 1.79 KB
/
upload.py
File metadata and controls
48 lines (38 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions
import openpyxl
def update_excel_data(filePath, searchTerm, colName, new_value):
book = openpyxl.load_workbook(filePath)
sheet = book.active
Dict = {}
for i in range(1, sheet.max_column + 1):
if sheet.cell(row=1, column=i).value == colName:
Dict["col"] = i
for i in range(1, sheet.max_row + 1):
for j in range(1, sheet.max_column + 1):
if sheet.cell(row=i, column=j).value == searchTerm:
Dict["row"] = i
sheet.cell(row=Dict["row"], column=Dict["col"]).value = new_value
book.save(file_path)
file_path = "/Users/mohammad.faiz/Downloads/file_to_file_input.xlsx"
fruit_name = "Apple"
newValue = "990"
driver = webdriver.Chrome()
driver.implicitly_wait(5)
driver.get("https://rahulshettyacademy.com/upload-download-test/index.html")
driver.find_element(By.ID, "downloadButton").click()
# edit the excel with updated value
update_excel_data(file_path, fruit_name, "price", newValue)
# upload
file_input = driver.find_element(By.CSS_SELECTOR, "input[type='file']")
file_input.send_keys(file_path)
wait = WebDriverWait(driver, 5)
toast_locator = (By.CSS_SELECTOR, ".Toastify__toast-body div:nth-child(2)")
wait.until(expected_conditions.visibility_of_element_located(toast_locator))
print(driver.find_element(*toast_locator).text)
priceColumn = driver.find_element(By.XPATH, "//div[text()='Price']").get_attribute("data-column-id")
actual_price = driver.find_element(By.XPATH,
"//div[text()='" + fruit_name + "']/parent::div/parent::div/div[@id='cell-" + priceColumn + "-undefined']").text
assert actual_price == newValue