0

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 html html

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

zeppelin11
  • 103
  • 2
  • 3
  • 9
  • Have you tried debugging and stepping through each step? – King11 Oct 22 '19 at 20:07
  • The last line is the one that is not working but I don't know how to debug it since it is a single line code and it should work. driver.find_element_by_css_selector("i[class='ion-android-checkbox-outline-blank']").click() -``` – zeppelin11 Oct 22 '19 at 20:13
  • Create a variable and see if that variable is the item you want clicked. Such as `var temp = driver.find_element_by_css_selector("i[class='ion-android-checkbox-outline-blank']")`. See if that's the element you want and then call `temp.click();` to test if it does what it needs to do. Just try breaking it up into smaller parts to see whats the part that not working correctly for you. – King11 Oct 22 '19 at 20:15
  • It should be that variable since it is working properly in the second line, clicking on the checkbox. Don't you think? – zeppelin11 Oct 22 '19 at 20:17
  • Since those lines are the same, wouldn't it be easier to just make a variable of that line as in my previous comment, and just call `temp.click()` at those two lines? Also have you tried getting the element another way besides by css_selector? – King11 Oct 22 '19 at 20:19
  • Try clicking using different method. (link)https://stackoverflow.com/questions/44912203/selenium-web-driver-java-element-is-not-clickable-at-point-x-y-other-elem , when .click() doesn't work I use second method and it works like charm everytime. Hope it helps you. – Pratik Oct 22 '19 at 20:24
  • You can also try to find the element by css selector this way: `driver.findElement(By.cssSelector("i[class='ion-android-checkbox-outline-blank']"));` It wont hurt to try it out to see if you get a different result somehow. or use Actions if all else fails. – King11 Oct 22 '19 at 20:26
  • already tried executeScript but same happens. just tried temp.click(), also same happened. It does not give any error but also do not select the checkbox in the second time. I also tried xpath("/html/body/app/main/app/div/div//e-arsiv/taslaklar/div[3]/div[3]/div/div/i") but it is giving NoSuchElementException – zeppelin11 Oct 22 '19 at 20:38
  • try using xpath = `.//div[@class='select-action']/i` or you specifically want to you css? – Pratik Oct 22 '19 at 20:49

2 Answers2

0

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.

King11
  • 1,239
  • 3
  • 9
  • 17
  • sorry I'm a total newbie but it gives syntax error for temp. Adding the screenshot to the question. – zeppelin11 Oct 22 '19 at 20:50
  • What is the error exactly? And no need to apologize :) – King11 Oct 22 '19 at 20:54
  • I changed the `driver.find.Element...` line. try using what I just edited – King11 Oct 22 '19 at 20:57
  • manged to run but getting this one now: "line 52, in temp = driver.findElement(By.cssSelector("i[class='ion-android-checkbox-outline-blank']")) AttributeError: 'WebDriver' object has no attribute 'findElement' – zeppelin11 Oct 22 '19 at 21:20
  • Solved that issue by `temp = driver.find_element(By.XPATH, "//e-arsiv/taslaklar/div[4]/div[3]/div/div/i")` However, now getting **NameError: name 'Actions' is not defined**. Should I import a specific class? – zeppelin11 Oct 22 '19 at 22:20
  • Yes, you're missing the import. Also I should've noticed earlier but you're using python. So you would be using `ActionChains` instead of just `Action`. I've updated my answer, try it out now. – King11 Oct 23 '19 at 04:23
  • Thanks! It worked again for the first time but for the second `action.click(temp).perform()` giving *StaleElementReferenceException*. In order to solve that error ı tried this loop `retryingFindClick2(by): attempts=0 while (attempts < 100): try: action.click(by).perform() result = True break except StaleElementReferenceException: attempts= attempts + 1 return result` It soleve the error but again didn't perfom the checkbox clicking – zeppelin11 Oct 23 '19 at 07:29
  • Found the solution by refreshing the browser every time – zeppelin11 Oct 23 '19 at 13:31
  • great that you found the solution. If you found it while using my answer, could you mark this as the the accepted answer so the question can be resolved and closed? – King11 Oct 24 '19 at 13:33
0

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.

ashwinin
  • 81
  • 5