简体   繁体   中英

Clicking on a checkbox works the first time but not the second [Selenium]

So there are invoices I need to issue.

First, I click on the checkbox to select all invoices on the current page. Then I click on the issue button, and finally approve them to be issued.

Once the current invoices issued, the ones on the next page appear automatically.

I want to repeat the same process for the next ones but I can't click on the checkbox as I did the first time. Nothing happens, it doesn't give any error. Just nothing happens.

Here is the htmlhtml

@King11 ss

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

Edit: I found the solution by writing a loop that refreshing the browser every time it issued invoices

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")

Try using ActionsChains . First you would have to import it using the line:

from selenium.webdriver.common.action_chains import ActionChains

 time.sleep(8) --wait until invoice screen appears
 WebElement temp = driver.findElement(By.cssSelector("i[class='ion-android-checkbox-outline-blank']"));
 action=ActionChains(driver)
 action.click(temp).preform(); --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

 action.click(temp).preform(); 

Hopefully this helps.

Please wait until the checkbox element becomes clickable and then perform the click.

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

There is no other reason this can fail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM