This question is an exact duplicate of:
Hi I'm trying to create a click robot The program runs half way and it stops running but it maintains at the running status.
Description of the code: it's a code that gets the links that in the particular webpage and click accordingly
But the code get the attribute and stuck midway.
I'm suspecting a memory leak or the python system has a bit of a problem but I'm not too sure.
Here is what I have
from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import csv
import urllib.parse
url = 'https://shopee.com.my/'
driver = webdriver.Chrome('E:/users/Asashin/Desktop/Bots/others/chromedriver.exe')
driver.get(url)
actions = ActionChains(driver)
wait = WebDriverWait(driver, 10)
time.sleep(1)
lan=driver.find_element_by_xpath('//button[text()="English"]')
if lan.is_displayed:
lan.click()
time.sleep(0.5)
ads=driver.find_element_by_class_name('shopee-popup__close-btn')
if ads.is_displayed:
ads.click()
time.sleep(0.5)
time.sleep(2)
def clickpy():
for x in range(10):
driver.execute_script("window.scrollBy(0,300)")
time.sleep(0.1)
# get all links (without clicking)
all_items = driver.find_elements_by_xpath('//a[@data-sqe="link"]')
all_urls = []
time.sleep(0.8)
for item in all_items:
# This give you whole url of the anchor tag
url = item.get_attribute('href')
if "-Dr.Alstone-" in url:
continue
else:
if "-Dr.-Alstone-" in url:
continue
else:
if "/Dr.Alstone-" in url:
continue
else:
if "-Simoni-" in url:
continue
else:
if "-Lütfy-" in url:
continue
else:
# You need to remove the preceding values in order to verify href later for clicking
urlfinal=url.split('https://shopee.com.my')[1]
try:
c = urllib.parse.unquote(urlfinal)
all_urls.append(c)
except:
all_urls.append(urlfinal)
print(all_urls)
a= len(all_urls)
print('len:' + str(a))
# now use links
i = 0
j= a-5
try:
while i <= 4 :
#Identify the parent tag by child tag use following Xpath.
try:
item.sleep(0.8)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='col-xs-2-4 shopee-search-item-result__item' and @data-sqe='item'][.//a[@data-sqe='link' and @href='" + all_urls[i] +"']]"))).click()
time.sleep(0.8)
driver.back()
except:
continue
i+=1
except:
while j <= a :
try:
item.sleep(0.8)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='col-xs-2-4 shopee-search-item-result__item' and @data-sqe='item'][.//a[@data-sqe='link' and @href='" + all_urls[j] +"']]"))).click()
time.sleep(0.8)
driver.back()
except:
continue
j+=1
while j <= a :
try:
time.sleep(0.8)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='col-xs-2-4 shopee-search-item-result__item' and @data-sqe='item'][.//a[@data-sqe='link' and @href='" + all_urls[j] +"']]"))).click()
time.sleep(0.8)
driver.back()
except:
continue
j+=1
def inputsearch(x):
firstLevelMenu1 = driver.find_element_by_class_name('shopee-searchbar__main')
actions.move_to_element(firstLevelMenu1).click();
secondLevelMenu1 = driver.find_element_by_class_name('shopee-searchbar-input__input');
secondLevelMenu1.send_keys(x);
def inputdelete():
firstLevelMenu1 = driver.find_element_by_class_name('shopee-searchbar__main')
actions.move_to_element(firstLevelMenu1).click();
secondLevelMenu1 = driver.find_element_by_class_name('shopee-searchbar-input__input');
secondLevelMenu1.clear();
firstLevelMenu = driver.find_element_by_xpath('//ul[@class="navbar__links"]')
actions.move_to_element(firstLevelMenu).perform();
secondLevelMenu = driver.find_element_by_xpath('//li[contains(text(), "Login")]');
secondLevelMenu.click();
time.sleep(3)
f= open("accounts.csv","r")
for line in f :
fields = line.split(",")
a = fields[0]
b = fields[1]
c = fields[2]
driver.find_element_by_xpath("//input[@type='text']").send_keys(str(a))
driver.find_element_by_xpath("//input[@type='password']").send_keys(str(c))
time.sleep(0.8)
button = driver.find_element_by_xpath('//button[@class="_1BMmPI _37G57D _7h_6kj _1qIIqG _3JP5il"]')
if button.is_displayed:
button.click()
time.sleep(2)
else:
continue
time.sleep(1)
ads2=driver.find_element_by_class_name('shopee-popup__close-btn')
if ads2.is_displayed:
ads2.click()
time.sleep(0.5)
try:
banned = driver.switch_to_alert.text("Your account has been banned")
banned2 = driver.switch_to_alert.text("Invalid Email")
if banned.is_displayed():
while True:
q= open ('Banned Accounts.txt',w)
File_object.write(a)
driver.get_element_by_class_name('input-with-status__input').clear()
driver.find_element_by_xpath("//input[@type='password']").clear()
continue
except:
time.sleep(3)
inputsearch('Mattress')
time.sleep(1)
driver.find_element_by_xpath('//button[@class="btn btn-solid-primary btn--s btn--inline"]').click()
time.sleep(1.5)
clickpy()
time.sleep(2)
inputdelete()
inputsearch('Pillows')
time.sleep(1)
driver.find_element_by_xpath('//button[@class="btn btn-solid-primary btn--s btn--inline"]').click()
time.sleep(1.5)
clickpy()
time.sleep(1.5)
firstLevelMenu2 = driver.find_element_by_xpath('//ul[@class="navbar__links"]')
actions.move_to_element(firstLevelMenu).perform();
secondLevelMenu2 = driver.find_element_by_xpath('//li[@class = "navbar__link-text navbar__link-text--normal-case"]');
actions.move_to_element(secondLevelMenu).perform();
time.sleep(0.5)
thirdLevelMenu3 = driver.find_elememt_by_xpath('.//div[@class="navbar-account-drawer__button navbar-account-drawer__button--complement"]')
thirdLevelMenu3.click()
here is the account names and password:
The thing is that I've tried the hover method it doesn't seem to work. The div class is made of hovering method and the drop-down menu will only happen together with the logout menu. How can it be solved?