Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

C++向けのWebdriverを使うときにElement_id length is invalidのエラーが発生しました。

解決したいこと

C++用Selenium Webdriverライブライリーを使ってウェブスクリプトを書くときにエラーが発生しました。
https://github.com/durdyev/webdriverxx

該当するソースコード

#include <iostream>
#include <windows.h>
#include "webdriverxx/webdriver.h"
#include "webdriverxx/browsers/chrome.h"
#include "webdriverxx/browsers/ie.h"
#include "webdriverxx/wait.h"
using namespace webdriverxx;
int main()
{
    WebDriver driver = Start(Chrome());
    auto elem = driver.Navigate("http://google.com")
        .FindElement(ByCss("input[name=q]"));

    elem.Click(); // ここで例外発生

    system("pause");
    return 0;
}

発生している問題・エラー

Server failed to execute command (message: no such element: Element_id length is invalid
  (Session info: chrome=109.0.5414.120)
For documentation on this error, please visit: https://selenium.dev/exceptions/#no_such_element
Build info: version: '4.8.0', revision: '267030adea'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '18.0.1'
Driver info: driver.version: unknown, status: An element could not be located on the page using the given search parameters., status_code: 7) at line 187, file C:\Users\zhirong\source\repos\webdriver\webdriver\webdriverxx\detail\resource.h called from webdriverxx::detail::Resource::ProcessResponse (HTTP code: 500, body: {
  "state": "no such element",
  "sessionId": null,
  "class": "org.openqa.selenium.remote.Response",
  "value": {
    "additionalInformation": "Driver info: driver.version: unknown",
    "localizedMessage": "no such element: Element_id length is invalid\n  (Session info: chrome=109.0.5414.120)\nFor documentation on this error, please visit: https:\u002f\u002fselenium.dev\u002fexceptions\u002f#no_such_element\nBuild info: version: '4.8.0', revision: '267030adea'\nSystem info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '18.0.1'\nDriver info: driver.version: unknown",
    "supportUrl": "https:\u002f\u002fselenium.dev\u002fexceptions\u002f#no_such_element",
    "systemInformation": "System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '18.0.1'",
    "cause": null,
    "stackTrace": [
      {
        "fileName": "DirectConstructorHandleAccessor.java",
        "moduleVersion": "18.0.1",
        "nativeMethod": false,
        "moduleName": "java.base",
        "methodName": "newInstance",
        "className": "jdk.internal.reflect.DirectConstructorHandleAccessor",
        "lineNumber": 67,
        "class": "java.lang.StackTraceElement",
        "classLoaderName": null
      },
      {
        "fileName": "Constructor.java",
        "moduleVersion": "18.0.1",
        "nativeMethod": false,
        "moduleName": "java.base",
        "methodName": "newInstanceWithCaller",
        "className": "java.lang.reflect.Constructor",
        "lineNumber": 499,
        "class": "java.lang.StackTraceElement",
        "classLoaderName": null
      },
...

例外が発生する箇所

image.png

自分で試したこと

Click()、SendKeys()、GetText()など、ウェブページのエレメントを取得した後それに対してこれらのメソッドを使うと決まって上記のElement_id length is invalidのエラーが発生します。

開発環境

OS:Window 10
IDE:Visual Studio 2022
curlバージョン:curl-7.87.0
seleniumバージョン:selenium-server-4.8.0

0 likes

1Answer

C++用Selenium は知らないですが、

auto elem = driver.Navigate("http://google.com").FindElement(ByCss("input[name=q]"));
elem.Click(); 

ByCss("input[name=q]")
は参照できても、Click()は出来ないのでは?
F12キーで取得できるxPathを指定してはどうでしょうか?

0Like

Comments

  1. @gaox1234567

    Questioner

    xpath,name,class,ほとんど全ての取得方法を試したが同じエラーが表示します。

Your answer might help someone💌