从ExecuteScript从JavaScriptExecutor获取价值 [英] Get Value from ExecuteScript from JavaScriptExecutor

查看:1629
本文介绍了从ExecuteScript从JavaScriptExecutor获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我需要从

 字符串someValue中=((IJavaScriptExecutor)Global.Driver).ExecuteScript($('#publication_title)VAL(););

Console.WriteLine(someValue中);
 

你知道吗?

解决方案

 字符串someValue中=((IJavaScriptExecutor)Global.Driver).ExecuteScript(返回$('#publication_title)。 VAL(););
 

是你在找什么。它需要多一点推,告诉它得到这个值,并还给我。

我也想说,你可能甚至都不需要做到这一点。如果你正在努力,以获得值的元素属性,这是更好地做:

  element.GetAttribute(价值);
 

I have a issue i need value from

string someValue = ((IJavaScriptExecutor)Global.Driver).ExecuteScript("$('#publication_title').val();");

Console.WriteLine(someValue);

Any idea?

解决方案

string someValue = ((IJavaScriptExecutor)Global.Driver).ExecuteScript("return $('#publication_title').val();");

Is what you are looking for. It needs a little more "pushing" to tell it "get this value and give it back to me".

I'd also say you probably don't even need to do this. If you are struggling to get the value property of an element, it's better to do:

element.GetAttribute("value");

这篇关于从ExecuteScript从JavaScriptExecutor获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆