Swipe while not found C#

#1

Hi,
I am having troubles on locate an element not on the screen using the following command

driver.ExecuteScript("seetest:client.swipeWhileNotFound(\"Down\", 0, 2000, \"NATIVE\", \"xpath=[elem_to_be_found]\", 0, 1000, 5, true)");

The problem is, the element is found but the click is not performed. So the command finds the element but is unable to click it.
I’ve tried a solution proposed on this discussion (I report a modified version of the code here)

AppiumWebElement elemToclick;

while(1==1)
{
  driver.ExecuteScript("client:client.swipe(\"Down\", 30, 500)");
  elemToclick = driver.FindElementByXPath(itemXPath)

  if(elemToclick.Displayed)
    break;
}

elemToclick.Click();
wait.Until(ExpectedConditions.ElementExists(By.XPath([Page_To_Appear_After_the_click])));

The element seems to be found and clicked but neither the element appear on the sceen nor the effect of the click is visible. Meaning the page that should appear after the click is not loaded on the sceen.

I know an element is found even if is not visible on the sceen but the condition

if(elemToclick.Displayed)

is supposed to make the swipe to continue until the element is actually visible, isnt’ it?

Anyway, this does not pruduce the effect I wanted, which is

swipe the screen until the element is actually visible
click on the element
make the click effect visible on the sceen

any ideas?

0 Likes

#2

Hi @vins_delta ,

Can you try to include the following attribute @onScreen=‘true’ . So sometime likes this:

driver.executeScript(“seetest:client.swipeWhileNotFound(“Down”, 0, 2000, “xpath=//*[@id=‘element’ and @onScreen=‘true’]”, 0, 1000, 5, “true”)”);

I am not sure if this is what it is, but sometimes elements will be loaded as part of the page / hierarchy, even if they are not visible on the screen itself. We have properties such as onScreen and visible which you can use in combination with your xpath to make sure you are only trying to work with an element that is ACTUALLY visible on the screen.

0 Likes

#3

Hi rahee. Thanks for your answer.

I tried by adding both attributes, so the xpath becames:

xpath=//*[@id=‘element’ and @onScreen=‘true’]

xpath=//*[@id=‘element’ and @visible=‘true’]

the behaviour is the same anyway, the element is found but not clicked.

With the first path, the screen is not swapped but the answer is found: true;
with the second path, the screen is swapped and the element is not even found, answer is found: false.

I extracted the element’s attributes with object spy and observed they are always the same, either before or after the swipe. That is for example, the attribute

“onScreen” is true before and after the swipe,

id doesn’t matter if the element is actually visible on the screen.
For the attribute “visible” is dos not even exist.

I also tried this

bool found = driver.FindElementByXPath("XPATH").Displayed;

it is always true! Before or After the Swipe

So apparently, the object property do not change.

I found that the behaviour is different on different elements: if the element to be found is a button, it does not work, while if the element is a link, then the element is found and clicked.
Is that normal?

0 Likes