-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuber.py
More file actions
87 lines (73 loc) · 3.03 KB
/
Copy pathuber.py
File metadata and controls
87 lines (73 loc) · 3.03 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Generated by Selenium IDE
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import pandas as pd
import numpy as np
import xlsxwriter
class TestTest():
driver_url = ""
def setup_method(self, method):
self.driver = webdriver.Chrome(executable_path=self.driver_url)
self.vars = {}
def teardown_method(self, method):
self.driver.quit()
def test_test(self):
# Test name: test
# Step # | name | target | value | comment
# 1 | open | / | |
self.driver.get("https://www.ubereats.com/en-US/")
# 2 | setWindowSize | 1674x954 | |
self.driver.set_window_size(1674, 954)
# 3 | mouseOver | css=.b4:nth-child(2) > svg > path | |
delay = 30
try:
WebDriverWait(self.driver, delay).until(
EC.presence_of_element_located((By.ID, "location-enter-address-input")))
print("Page is ready!")
except TimeoutException:
print("Loading took too much time!")
# 3 | click | id=location-enter-address-input | |
self.driver.find_element(By.ID, "location-enter-address-input").click()
# 4 | type | id=location-enter-address-input | NY |
self.driver.find_element(By.ID, "location-enter-address-input").send_keys("NY")
# webderiver delay
time.sleep(5)
#restaurant list tag
try:
WebDriverWait(self.driver, delay).until(
EC.presence_of_element_located((By.ID, "location-enter-address-menu")))
print("Restaurant List Tag is ready!")
except TimeoutException:
print("Finding Restaurant too much time!")
restaurant_ele = self.driver.find_element(By.ID, "location-enter-address-menu")
#restaurant tag
df = pd.DataFrame({},
columns = ['Name', 'Address'])
items = restaurant_ele.find_elements_by_tag_name("li")
cnt = 0
name = ''
address = ''
for item in items:
div_ele = item.find_elements_by_class_name("b4")
tmp = []
for div_item in div_ele:
tmp.append(div_item.text)
df = df.append({'Name': tmp[0], 'Address': tmp[1]}, ignore_index=True)
print(df)
#Restaurant File
# Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pd.ExcelWriter("restaurant_list.xlsx", engine='xlsxwriter')
# Convert the dataframe to an XlsxWriter Excel object.
df.to_excel(writer, sheet_name='Sheet1', index=False)
workbook = writer.book
worksheet = writer.sheets['Sheet1']
# Close the Pandas Excel writer and output the Excel file.
writer.save()