-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeweggMethods.py
38 lines (31 loc) · 997 Bytes
/
NeweggMethods.py
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
# install selenium
# install chromedriver and copy executable to C:/Program Files (x86)
import time
import CommonMethods
from selenium.common.exceptions import NoSuchElementException
driver = CommonMethods.driver
def tryclosepopup(popupid):
try:
driver.find_element_by_id(popupid).click()
except NoSuchElementException:
pass
def newegg(productUrl, refreshrate):
CommonMethods.setuserinfo()
print("Navigating to product page . . .")
# open site
try:
driver.get(productUrl)
except Exception:
print(">The site URL you entered was not valid. Please restart the program and try again.<")
exit(-1)
# try to add to cart
while True:
time.sleep(refreshrate)
tryclosepopup('popup-close')
time.sleep(1)
cartbutton = driver.find_element_by_class_name('btn-primary')
if cartbutton.is_enabled():
cartbutton.click()
break
else:
driver.refresh()