Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';t在selenium中将对象转换为字符串_Javascript_Node.js_Selenium_Selenium Webdriver_Tostring - Fatal编程技术网

Javascript Can';t在selenium中将对象转换为字符串

Javascript Can';t在selenium中将对象转换为字符串,javascript,node.js,selenium,selenium-webdriver,tostring,Javascript,Node.js,Selenium,Selenium Webdriver,Tostring,在文档中,这非常简单,但使用selenium pack从网站获取变量是有问题的(正如我现在需要做的)。问题是console.log()将其作为一个对象返回,但没有我想要的参数(可以看到,客户机的数量正好是string/int(删除/) HTML的网页和字符串我正在寻找 以及我从console.log获得的信息 [ thenableWebDriverProxy { flow_: ControlFlow { propagateUnhandledRejections

在文档中,这非常简单,但使用selenium pack从网站获取变量是有问题的(正如我现在需要做的)。问题是console.log()将其作为一个对象返回,但没有我想要的参数(可以看到,客户机的数量正好是string/int(删除/)

HTML的网页和字符串我正在寻找

以及我从console.log获得的信息

[ thenableWebDriverProxy {
    flow_:
     ControlFlow {
       propagateUnhandledRejections_: true,
       activeQueue_: [Object],
       taskQueues_: [Object],
       shutdownTask_: null,
       hold_: [Object] },
    session_:
     ManagedPromise {
       flow_: [Object],
       stack_: null,
       parent_: [Object],
       callbacks_: [Object],
       state_: 'blocked',
       handled_: true,
       value_: undefined,
       queue_: null },
    executor_: Executor { w3c: false, customCommands_: [Object], log_: [Object] },
    fileDetector_: null,
    onQuit_: [Function: onQuit],
    cancel: [Function],
    then: [Function: bound then],
    catch: [Function: bound then] },
  ManagedPromise {
    flow_:
     ControlFlow {
       propagateUnhandledRejections_: true,
       activeQueue_: [Object],
       taskQueues_: [Object],
       shutdownTask_: null,
       hold_: [Object] },
    stack_: null,
    parent_: null,
    callbacks_: null,
    state_: 'fulfilled',
    handled_: false,
    value_: 'unused',
    queue_:
     TaskQueue {
       name_: 'TaskQueue::3',
       flow_: [Object],
       tasks_: [Object],
       interrupts_: null,
       pending_: null,
       subQ_: null,
       state_: 'new',
       unhandledRejections_: Set {} } },
  [Function],
  [Function: bound then],
  [Function: bound catch],
  [Function] ]
使用console.log(number.getText())后的输出

ManagedPromise{
流程图:
控制流{
传播未处理的弹出内容:true,
活动队列:
任务队列{
名称:'TaskQueue::3',
流量:[循环],
任务:[对象],
中断:空,
挂起:null,
subQ_u2;:空,
声明:“新”,
未处理的弹出项:集合{},
任务队列:集合{[Object]},
关机任务:空,
举行会议:
超时{
_叫:假,,
_空闲时间:2147483647,
_idlePrev:[对象],
_idleNext:[对象],
_idleStart:431,
_onTimeout:[函数],
_计时器:未定义,
_重复:2147483647},
堆栈地址:
{任务:WebElement.getText()
在EnableWebDriverProxy.schedule(/home/soda/node_modules/selenium webdriver/lib/webdriver.js:816:17)中
在WebElementPromise.schedule上(/home/soda/node\u modules/selenium-webdriver/lib/webdriver.js:1921:25)
在WebElementPromise.getText(/home/soda/node_modules/selenium-webdriver/lib/webdriver.js:2185:17)
在getNumber(/home/soda/main.js:15:24)
在对象上。(/home/soda/main.js:19:1)
在模块处编译(Module.js:573:32)
在Object.Module.\u extensions..js(Module.js:582:10)
在Module.load(Module.js:490:32)
在tryModuleLoad时(module.js:449:12)
在Function.Module.\u load(Module.js:441:3)name:'Task'},
父项:null,
回调:null,
声明:“待定”,
错误:,
值:未定义,
队列:空}

number
WebElement
,当您使用
toString()
时,您得到的是对象字符串,而不是文本。对于文本,请使用
getText()


number
WebElement
,当您使用
toString()
时,您得到的是对象字符串,而不是文本。对于文本,请使用
getText()

.getText()返回一个承诺,因此为了获取文本,需要使用.then()从承诺中提取值

.getText()返回一个承诺,因此为了获取文本,需要使用.then()从承诺中提取值


任务:WebElementPromise.schedule上的tablewebdriverproxy.schedule(/node\u modules/selenium webdriver/lib/webdriver.js:816:17)WebElementPromise.schedule上的WebElement.getText(),WebElementPromise.getText(/node\u modules/selenium webdriver/lib/webdriver.js:2185:17)对象上的getNumber(/main.js:15:24)。(/main.js:19:1)at Module._compile(Module.js:573:32)at Object.Module._extensions..js(Module.js:582:10)at Module.load(Module.js:490:32)at tryModuleLoad(Module.js:449:12)at Function.Module._load(Module.js:441:3)name:'Task'},它没有修复任何东西,只是那个输出(对不起,不想编辑整个帖子)@Myszsoda它看起来像是一条异常消息,但不包括原因。这是完整的消息吗?@Myszsoda Try
number=driver.findelelement(By.xpath('/html/body/table/tbody/tr[4]/td[2]/table/tbody/tr/td[1]/table/tbody/tr[15]/td[2]')。getText();console.log(number)
也许它与console.log@Myszsoda
driver.findElement(通过.xpath('/html/body/table/tbody/tr[4]/td[2]/table/tbody/tr/td[1]/table/tbody/tr[15]/td[2]'))有关。getText();
任务:WebElement.getText()位于tablewebdriverproxy.schedule(/node\u modules/selenium/webdriver/lib/webdriver.js:816:17)在WebElementPromise.schedule(/node\u modules/selenium webdriver/lib/webdriver.js:1921:25)在WebElementPromise.getText(/node\u modules/selenium webdriver/lib/webdriver.js:2185:17)在getNumber(/main.js:15:24)在Object.(/main.js:19:1)在Object.Module.\u编译(Module.js:573:32)在Object.Module.Module.\u扩展名...js:582:10)在Module.load(module.js:490:32)在tryModuleLoad(module.js:449:12)在Function.module.\u load(module.js:441:3)name:'Task'},它没有修复任何东西,只是那个输出(抱歉,不想编辑整个帖子)@Myszsoda它看起来像是一条异常消息,但不包括原因。这是完整的消息吗?@Myszsoda Try
number=driver.findelelement(By.xpath('/html/body/table/tbody/tr[4]/td[2]/table/tbody/tr/td[1]/table/tbody/tr[15]/td[2]')。getText();console.log(number)
也许它与console.log@Myszsoda
driver.findelelement(By.xpath('/html/body/table/tbody/tr[4]/td[2]/table/tbody/tr/td[1]/table/tbody/tr[15]/td[2]'))有关。getText();
[ thenableWebDriverProxy {
    flow_:
     ControlFlow {
       propagateUnhandledRejections_: true,
       activeQueue_: [Object],
       taskQueues_: [Object],
       shutdownTask_: null,
       hold_: [Object] },
    session_:
     ManagedPromise {
       flow_: [Object],
       stack_: null,
       parent_: [Object],
       callbacks_: [Object],
       state_: 'blocked',
       handled_: true,
       value_: undefined,
       queue_: null },
    executor_: Executor { w3c: false, customCommands_: [Object], log_: [Object] },
    fileDetector_: null,
    onQuit_: [Function: onQuit],
    cancel: [Function],
    then: [Function: bound then],
    catch: [Function: bound then] },
  ManagedPromise {
    flow_:
     ControlFlow {
       propagateUnhandledRejections_: true,
       activeQueue_: [Object],
       taskQueues_: [Object],
       shutdownTask_: null,
       hold_: [Object] },
    stack_: null,
    parent_: null,
    callbacks_: null,
    state_: 'fulfilled',
    handled_: false,
    value_: 'unused',
    queue_:
     TaskQueue {
       name_: 'TaskQueue::3',
       flow_: [Object],
       tasks_: [Object],
       interrupts_: null,
       pending_: null,
       subQ_: null,
       state_: 'new',
       unhandledRejections_: Set {} } },
  [Function],
  [Function: bound then],
  [Function: bound catch],
  [Function] ]
ManagedPromise {
  flow_:
   ControlFlow {
     propagateUnhandledRejections_: true,
     activeQueue_:
      TaskQueue {
        name_: 'TaskQueue::3',
        flow_: [Circular],
        tasks_: [Object],
        interrupts_: null,
        pending_: null,
        subQ_: null,
        state_: 'new',
        unhandledRejections_: Set {} },
     taskQueues_: Set { [Object] },
     shutdownTask_: null,
     hold_:
      Timeout {
        _called: false,
        _idleTimeout: 2147483647,
        _idlePrev: [Object],
        _idleNext: [Object],
        _idleStart: 431,
        _onTimeout: [Function],
        _timerArgs: undefined,
        _repeat: 2147483647 } },
  stack_:
   { Task: WebElement.getText()
       at thenableWebDriverProxy.schedule (/home/soda/node_modules/selenium-webdriver/lib/webdriver.js:816:17)
       at WebElementPromise.schedule_ (/home/soda/node_modules/selenium-webdriver/lib/webdriver.js:1921:25)
       at WebElementPromise.getText (/home/soda/node_modules/selenium-webdriver/lib/webdriver.js:2185:17)
       at getNumber (/home/soda/main.js:15:24)
       at Object.<anonymous> (/home/soda/main.js:19:1)
       at Module._compile (module.js:573:32)
       at Object.Module._extensions..js (module.js:582:10)
       at Module.load (module.js:490:32)
       at tryModuleLoad (module.js:449:12)
       at Function.Module._load (module.js:441:3) name: 'Task' },
  parent_: null,
  callbacks_: null,
  state_: 'pending',
  handled_: false,
  value_: undefined,
  queue_: null }
number = driver.findElement(By.xpath('/html/body/table/tbody/tr[4]/td[2]/table/tbody/tr/td[1]/table/tbody/tr[15]/td[2]')).getText();
console.log(number);
number = driver.findElement(By.xpath('/html/body/table/tbody/tr[4]/td[2]/table/tbody/tr/td[1]/table/tbody/tr[15]/td[2]')); //.toString is not working either, valueof too

number.then(function(text){
 console.log(text); //this will log the actual text.
});