2

I have seen this question, but it is not exactly what i need.

I am trying to automate 2048 using Selenium. As you start to play, the class of elements changes. The Tiles which has the value have 3, or 4 different classes with below patterns:

tile tile-1024 tile-position-1-2 
tile tile-2 tile-position-4-1 tile-new
tile tile-8 tile-position-1-4 tile-merged

I am wondering how can i find all the elements which has this pattern in their class:

tile tile-[TEIL SCORE] tile-position-[Any Number]-[Any Number]

Here is my my HTML. Sorry for image, the chrome console does not allow me to copy it without expanding it:

enter image description here

1
  • Update the question with the relevant text based HTML along with your code trials Commented Sep 29, 2018 at 18:03

2 Answers 2

1

To find all the elements as per the pattern you can use the following cssSelector:

.tile[class^='tile-'][class^='tile-position-']
Sign up to request clarification or add additional context in comments.

2 Comments

i have 1 more question. if it loads several WebElement how can i get each of these elements?
I am not sure how loads several WebElement (as per your comment) is different from find all the elements (as per your question) of-coarse you need to use findElements() method and possibly WebDriverWait.
1

Adding regex is not possible in CSS. ONLY Available options are *,$,^. But you can search based on following, which is as per your criteria, but probably it will match almost all tiles:

div[class^='tile-'][class^='tile-position]

Instead you can be more specific by providing number and row of tile which you are specifically looking for, for ex tile having number 4 in row 2:

div[class^='tile-4'][class^='tile-position-2]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.