Re: CSS selector with variable id

50 views
Skip to first unread message
Message has been deleted

advanceau...@gmail.com

unread,
Dec 13, 2017, 1:27:05 PM12/13/17
to Selenium Users
Looks like your application is a JavaScript framework like Angular or ExtJS.
My suggestion would be : Never use ID for identifying element on those frameworks(unless it was set by your devs). These frameworks generate an id based on element load while deploying. You can never be sure next time the id is going to be the same.

Use other attributes of the element.




On Wednesday, December 13, 2017 at 12:00:19 PM UTC-6, timothy ma wrote:
Hi

I have a question about CSSSelector and my coding is below:


new Select(d.findElement(By.cssSelector("select[id^='Template'][id$='ctl00_wtBrokerPooledTeam_BrokerId']"))).selectByIndex(1);

//Click tick button in the row
d.findElement(By.className("fa-check")).click();
//Click add Brokers to Pooled Team
d.findElement(By.xpath("//*[contains(@id,'BrokerPooledTeamTable_AddRow')]")).click();
new Select(d.findElement(By.cssSelector("select[id^='Template'][id$='ctl02_wtBrokerPooledTeam_BrokerId']"))).selectByIndex(2);


I wonder if it is possible to make ct100, ct102 as ct+i where i is 100, 102 etc for increment.

I did try to make it as variable but syntax error lie [id$='ct'+i+'wtBrokerPooledTeam_BrokerId']

Please kindly advise
Message has been deleted

David

unread,
Dec 14, 2017, 3:42:03 PM12/14/17
to Selenium Users
If I'm not mistaken, you have a typo when you tried to parameterize the locator, the "wtBroker..." string should have an underscore "_" prefixed to it, based on looking at the original hard coded string values, unless the original had the typo.
Reply all
Reply to author
Forward
0 new messages