I have a function that sets a checkbox. It involves a couple of steps:
- var cb = FindElement(locator)
- if (cb.Selected != newValue)
- verify cb.Selected equals newValue.
I find that if I do all 4 steps within one method, they work fine.
I tried to code refactor. So I created method A with step1 in it and it calls method B( step 2 & 3 & 4). However, I start getting StaleElementException at Step 4.
1. A lot of people use try/catch to retry and it works.
2. In my specific, I find that if I have step 1 & 2 within one method, it is OK.
I don’t know the cause of the problem. I guess this has to do with web page using modal dialog. Click() seems to screw up the element. It seems like one must call .Selected() right after it FindElement().