Selenium Python,自动点击,直到出现另一个元素

时间:2017-02-09 18:26:45

标签: python function selenium selenium-chromedriver

我想让我的selenium webdriver在python中自动点击一个按钮,直到出现一个我可以点击的弹出窗口。我的代码看起来像这样:

cart_count = "0"

def add_to_cart_click():
"""
clicks to add to your cart
:return:
"""
   add=driver.find_element_by_xpath('//*[@id="pdp_addtocart_button"]')
   add.click()
   check_cart()

def check_cart():
"""
checks to see if you have the item inside your cart
:return:
"""
   global cart_count
   if cart_count == "0":
     update_cart_count()
     print(cart_count)
   if cart_count == "1":
      wait = ui.WebDriverWait(driver, 10)
      go_to_cart=wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@id='header_cart_button']")))
      go_to_cart.click()
      cart()
   else:
      print('IDK')

def update_cart_count():
"""
updates your cart when you got a pair, I think
:return:
"""

   global cart_count
   new_cart_count = driver.find_element_by_id('header_cart_count')
   cart_count = new_cart_count.text

然后它以正确的顺序调用函数,我做错了什么?在我看来,cart_count不会更新。如何让它有争议地检查并更新其价值?它通常打印出0 IDK 0 IDK然后停止,如果有人有想法请告诉我。谢谢

0 个答案:

没有答案
相关问题