Assert Javascript value in C# with Selenium -


i'm writing test webapp. @ 1 point in application webpage completed using javascript. testing i'm using visual studio 2012 nunit , selenium. want check if box id=j_idt13:jnumber has text value of sometext.

ijavascriptexecutor js = driver ijavascriptexecutor; string valoare = (string)js.executescript("return $('#j_idt13\\:jnumber').val();"); assert.istrue(valoare.equals("sometext")); 

i keep getting error:

"syntax error, unrecognized expression: unsupported pseudo:jnumber".

what missing here?

i know have works i'd caution avoid using javascript fetch value of element, in fact in general should avoided when doing tests except when there no other way want do. reason selenium supposed behave typical user would. typical users don't type javascript page or interact directly. goes using jquery tests should not assume jquery exists on page , functioning. selenium provides ability fetch values of fields i'd recommend rewrite code like:

driver.findelement(by.id("j_idt13:jnumber")).getattribute("value");


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -