首页 > 解决方案 > 单击复选框第一次有效,但第二次无效 [Selenium]

问题描述

所以我需要开具发票。

首先,我单击复选框以选择当前页面上的所有发票。然后我点击发行按钮,最后批准它们被发行。

当前发票发出后,下一页上的发票会自动出现。

我想为下一个重复相同的过程,但我无法像第一次那样单击复选框。什么都没有发生,它不会给出任何错误。只是什么都没有发生。

这是htmlhtml

@King11ss

time.sleep(8) --wait until invoice screen appears
driver.find_element_by_css_selector("i[class='ion-android-checkbox-outline-blank']").click() --selecting checkbox
driver.find_element_by_xpath("//button[contains(text(),'Sil')]").click() --clicking on the sent button
driver.find_element_by_xpath("//button[contains(text(),'Evet')]").click() --approve to sent
time.sleep(12) --wait till current invoices are sent and checkbox become re-eligible to select

driver.find_element_by_css_selector("i[class='ion-android-checkbox-outline-blank']").click() --select the check box second time. used javascript to eleminate GUI issues but it does not do clicking

编辑:我通过编写一个循环来找到解决方案,该循环在每次发出发票时刷新浏览器

def loopy(page_number):
        while (page_number>0):
                driver.refresh()
                time.sleep(5)

                element_1=driver.find_element_by_xpath("/html/body/app/main/app/div/div/e-arsiv/taslaklar/div[2]/div/div/div[3]/div/button")
                driver.execute_script("arguments[0].click();", element_1)

                element_2=driver.find_element_by_xpath("/html/body/app/main/app/div/div/e-arsiv/taslaklar/div[2]/div/div/div[3]/div/ul/button[7]")
                driver.execute_script("arguments[0].click();", element_2)

                driver.implicitly_wait(20)

                driver.find_element_by_css_selector ("uc-quick-filter[titleshort='3A'][type='3M']").click()

                driver.implicitly_wait(20)

                element_4=driver.find_element_by_xpath("/html/body/app/main/app/div/div/e-arsiv/taslaklar/div[2]/div/div/div[4]/div[2]/ul/button[text()='e-Arşiv']")
                driver.execute_script("arguments[0].click();", element_4)

                wait = WebDriverWait(driver, 40)

                temp = wait.until(EC.element_to_be_clickable((By.XPATH,"//e-arsiv/taslaklar/div[4]/div[3]/div/div/i")))
                action= ActionChains(driver)
                action.click(temp).perform()

                element_5=driver.find_element_by_xpath("//button[contains(text(),'Sil')]")
                driver.execute_script("arguments[0].click();", element_5)

                element_6=driver.find_element_by_xpath("//button[contains(text(),'Evet')]")
                driver.execute_script("arguments[0].click();", element_6)

                driver.implicitly_wait(20)

                service=driver.find_element_by_id('serviceLoading').get_attribute("style")


                while (service=='display: none;'):

                        driver.refresh()
                        page_number=page_number-1
                        time.sleep(5)


                        break

                else:
                        time.sleep(2)
                        service=driver.find_element_by_id('serviceLoading').get_attribute("style")

标签: javascriptpythonhtmlseleniumautomation

解决方案


请等待复选框元素变为可点击,然后执行点击。

element = WebDriverWait(driver, 10).until(
    driver.element_to_be_clickable((By.xpath, "//button[contains(text(),'Sil')]"));
element.click
)

没有其他原因会失败。


推荐阅读