Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium NoSuchElementException_Python_Selenium_Selenium Webdriver - Fatal编程技术网

Python Selenium NoSuchElementException

Python Selenium NoSuchElementException,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,我有以下代码: browser.find_element_by_css_selector('#bet').send_keys(2500) time.sleep(2) x = 0 while x < 100: browser.find_element_by_css_selector('#start_game').click() time.sleep(3) browser.find_element_by_css_selector('li.tile:nth-child(

我有以下代码:

browser.find_element_by_css_selector('#bet').send_keys(2500)
time.sleep(2)
x = 0
while x < 100: 
    browser.find_element_by_css_selector('#start_game').click()
    time.sleep(3)
    browser.find_element_by_css_selector('li.tile:nth-child('+str(random.randint(1, 25))+')').click()
    time.sleep(2)
    browser.find_element_by_css_selector('li.tile:nth-child('+str(random.randint(1, 25))+')').click()
    time.sleep(2)
    browser.find_element_by_css_selector('li.tile:nth-child('+str(random.randint(1, 25))+')').click()
    time.sleep(5)
    try:
        browser.find_element_by_css_selector('.cashout').click()
    except NoSuchElementException:
        browser.find_element_by_css_selector('#start_game').click()
    time.sleep(10)
    x = x+1

以防他点击炸弹和兑现似乎并没有开始一个新的游戏。。。但它不起作用。有人能帮我吗?

你真的需要切换到睡眠通话,而不是硬编码的睡眠通话

等待
兑现
元素变为可见,然后单击:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

try:
    element = WebDriverWait(browser, 10).until(
        EC.visibility_of_element_located((By.CSS_SELECTOR, ".cashout"))
    )
    element.click()
except TimeoutException:
    browser.find_element_by_css_selector('#start_game').click()

@不变的好吧,我现在帮不了你。我无法复制你看到的东西。我刚刚注意到你的情况可能有什么问题,希望能有所帮助。在第一线,他在点击元素后开始游戏,如果没有兑现,他从第一线开始一场游戏和另一场游戏。
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

try:
    element = WebDriverWait(browser, 10).until(
        EC.visibility_of_element_located((By.CSS_SELECTOR, ".cashout"))
    )
    element.click()
except TimeoutException:
    browser.find_element_by_css_selector('#start_game').click()