@@ -145,18 +145,23 @@ class SeleniumHelper {
145
145
/**
146
146
* List of useful xpath scopes for finding elements.
147
147
* @returns {object } An object mapping names to xpath strings.
148
+ * @note Do not check for an exact class name with `contains(@class, "foo")`: that will match `class="foo2"`.
149
+ * Instead, use `contains(concat(" ", @class, " "), " foo ")`, which in this example will correctly report that
150
+ * " foo2 " does not contain " foo ". Similarly, to check if an element has any class starting with "foo", use
151
+ * `contains(concat(" ", @class), " foo")`. Checking with `starts-with(@class, "foo")`, for example, will only
152
+ * work if the whole "class" attribute starts with "foo" -- it will fail if another class is listed first.
148
153
*/
149
154
get scope ( ) {
150
155
return {
151
156
blocksTab : "*[@id='react-tabs-1']" ,
152
157
costumesTab : "*[@id='react-tabs-3']" ,
153
- modal : '*[@class=" ReactModalPortal" ]' ,
154
- reportedValue : '*[@class=" blocklyDropDownContent" ]' ,
158
+ modal : '*[contains(concat(" ", @class, " "), " ReactModalPortal ") ]' ,
159
+ reportedValue : '*[contains(concat(" ", @class, " "), " blocklyDropDownContent ") ]' ,
155
160
soundsTab : "*[@id='react-tabs-5']" ,
156
- spriteTile : '*[starts-with( @class," react-contextmenu-wrapper")]' ,
157
- menuBar : '*[contains(@class," menu-bar_menu-bar_")]' ,
158
- monitors : '*[starts-with( @class," stage_monitor-wrapper ")]' ,
159
- contextMenu : '*[starts-with( @class," react-contextmenu")]'
161
+ spriteTile : '*[contains(concat(" ", @class, " "), " react-contextmenu-wrapper ")]' ,
162
+ menuBar : '*[contains(concat(" ", @class), " menu-bar_menu-bar_")]' ,
163
+ monitors : '*[contains(concat(" ", @class), " stage_monitor-wrapper_ ")]' ,
164
+ contextMenu : '*[contains(concat(" ", @class, " "), " react-contextmenu ")]'
160
165
} ;
161
166
}
162
167
@@ -343,9 +348,9 @@ class SeleniumHelper {
343
348
// then finally click the toolbox text.
344
349
try {
345
350
await this . setTitle ( `clickBlocksCategory ${ categoryText } ` ) ;
346
- await this . findByXpath ( '//div[contains(@class, "blocks_blocks ")]' ) ;
351
+ await this . findByXpath ( '//div[contains(concat(" ", @class) , " blocks_blocks_ ")]' ) ;
347
352
await this . driver . sleep ( 100 ) ;
348
- await this . clickText ( categoryText , 'div[contains(@class, "blocks_blocks ")]' ) ;
353
+ await this . clickText ( categoryText , 'div[contains(concat(" ", @class) , " blocks_blocks_ ")]' ) ;
349
354
await this . driver . sleep ( 500 ) ; // Wait for scroll to finish
350
355
} catch ( cause ) {
351
356
throw await enhanceError ( outerError , cause ) ;
0 commit comments