Re; CSS Selectior Help

42 views
Skip to first unread message

timothy ma

unread,
Jan 18, 2018, 1:45:35 PM1/18/18
to Selenium Users
Hi

I try to locate the dialogpopup with YES button:

<a id="Template_CtmTheme_wt7_block_wtMainContent_ConfirmationDialog_wt47_block_wt16" tabindex="45" class="conf-dialog-button gray" onclick="ConfirmationDialog_Cancel('Template_CtmTheme_wt7_block_wtMainContent_ConfirmationDialog_wt47_block_wtPopUpMainContainer','Template_CtmTheme_wt7_block_wtActions_wtCancelLink');return false;OsAjax(arguments[0] || window.event,'Template_CtmTheme_wt7_block_wtMainContent_ConfirmationDialog_wt47_block_wt16','Template_CtmTheme_wt7$block$wtMainContent$ConfirmationDialog_wt47$block$wt16','','__OSVSTATE,',''); return false;" href="#">No</a>



<a id="Template_CtmTheme_wt7_block_wtMainContent_ConfirmationDialog_wt47_block_wt8" tabindex="44" class="conf-dialog-button blue" onclick="ConfirmationDialog_Continue('Template_CtmTheme_wt7_block_wtMainContent_ConfirmationDialog_wt47_block_wtPopUpMainContainer','Template_CtmTheme_wt7_block_wtActions_wtCancelLink',clickTemplate_CtmTheme_wt7_block_wtActions_wtCancelLink);return false;OsAjax(arguments[0] || window.event,'Template_CtmTheme_wt7_block_wtMainContent_ConfirmationDialog_wt47_block_wt8','Template_CtmTheme_wt7$block$wtMainContent$ConfirmationDialog_wt47$block$wt8','','__OSVSTATE,',''); return false;" href="#">Yes</a>

Now i need to hardcode it as

d.findElement(By.cssSelector("a[id*='ConfirmationDialog_wt47_block_wt8']")).click();

however the part wt47 and wt8 will be changing.

Is there any way to handle it better?

I did try:

d.findElement(By.cssSelector("a[onclick*='ConfirmationDialog_Continue'][id*='ConfirmationDialog']")).click();
d.findElement(By.cssSelector("a[id*='ConfirmationDialog'][class*='blue']")).click();
d.findElement(By.cssSelector("a[class^='conf'][class$='blue']")).click();

but no luck

Can I look at YES and NO directly?

Thanks

Chang Sui

unread,
Jan 18, 2018, 9:13:43 PM1/18/18
to Selenium Users
Maybe you can try to use the XPath?

timothy ma

unread,
Jan 19, 2018, 12:22:51 PM1/19/18
to Selenium Users
Chang

Thank you for your suggestion.

Can you show me how to use xpath  it in this example?

So far xpath also have limitation to handle underscore id eg. wt_123_button. It is reason I switch to CSSselector/

Tim

advanceau...@gmail.com

unread,
Jan 19, 2018, 12:40:57 PM1/19/18
to Selenium Users
Try these

1. If you know your application screen has only one Yes or No inside a <a> 
    
     a:contains('"Yes"')  
& a:contains('"No"')  

2.  a[class='conf-dialog-button gray'] :contains("Yes")  & a[class='conf-dialog-button blue'] :contains("No")

Jim Evans

unread,
Jan 19, 2018, 3:44:26 PM1/19/18
to Selenium Users
I’m sorry, but I cannot let that answer go. If you use the “:contains” pseudoselector and expect it to select elements via CSS selectors according to an element’s text, you’re going to have a bad time. The :contains selector is not a standard CSS selector, and is not guaranteed to work across browsers. It’s implemented by jQuery, but is not a standard; doing `document.querySelector(“:contains(‘foo’)”)` in the developer tools of your favorite browser is going to lead to an error, and therefore will do so when using Selenium also.
Reply all
Reply to author
Forward
0 new messages