Selenium: Determine status of WebElement by CssSelector

Question!

I am identifying a clickable WebElement by CssSelector. An example code I am using is:

String selectorString = "a.some-text.item";

WebElement we = driver.findElement(By.cssSelector(selectorString));
we.click();

The problem is, that after the item has been clicked its CssSelector changes to a.some-text.item.clicked. I can still securely identify it by using above selectorString variable. However, I only want to click it if it has not been clicked before.

How can I determine the items status, i.e. whether its cssSelector name is a.some-text.item or a.some-text.item.clicked?

By : nautical


Answers

I only want to click it if it has not been clicked before.

Try using :not(selector) function of cssSelector to determine only unclicked element :-

String selectorString = "a.some-text.item:not(.clicked)";

WebElement we = driver.findElement(By.cssSelector(selectorString));
we.click();

Edited :- If you want to just determine whether element has contains clicked class or not after clicking then try as below :-

String selectorString = "a.some-text.item";
driver.findElement(By.cssSelector(selectorString)).click();

//Now verify element clicked or not 
WebElement we = driver.findElement(By.cssSelector(selectorString));
String msg =  (we.getAttribute("class").contains("clicked")) ? "element clicked" : "element not clicked";
System.out.println(msg);


In my experience when the build stays greyed out and (processing) for longer than a few minutes it will stay forever like that. Best to just re-upload and wait for the new build to process. It does take a bit of time to show up for testing though.



This has happened to me a few times already i.e. when a binary doesn't finish processing due to connection drop or other issues (on apple side).

Just upload a new build and use that build for release or test flight. Don't worry about the build that never finishes. Just ignore it and move on.

If you are still seeing build 2 as the latest under testfligth section, then logout, clear your browser cache, log back in and see. Clearly your build 3 is the latest one. itunesconnect is super flaky.

Use apple support as a last resort. They will take days to solve something as simple as this.

By : Sam B


This video can help you solving your question :)
By: admin