H1テキストを取得したいとします。ページはmarkdownからHTMLに変換されます。私はエラーを取得していますSelenium + Cucumber + RubyのH1タグからテキストを取得する方法
element = driver.find_element(xpath: '/html/body/div[3]/div[1]/h1')
element.text
::私は、XPathを使用してテキストを取得するためのコードの下に使用している場合
<driver.find_element(xpath: '/html/body/div[3]/div[1]/h1')
Selenium::WebDriver::Error::NoSuchElementError: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[3]/div[1]/h1"}
(Session info: chrome=62.0.3202.89)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.1.7601 SP1 x86_64)
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.6.0/lib/selenium/webdriver/remote/response.rb:71:in `assert_ok'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.6.0/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.6.0/lib/selenium/webdriver/remote/http/common.rb:83:in `new'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.6.0/lib/selenium/webdriver/remote/http/common.rb:83:in `create_response'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.6.0/lib/selenium/webdriver/remote/http/default.rb:106:in `request'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.6.0/lib/selenium/webdriver/remote/http/common.rb:61:in `call'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.6.0/lib/selenium/webdriver/remote/bridge.rb:170:in `execute'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.6.0/lib/selenium/webdriver/remote/oss/bridge.rb:581:in `execute'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.6.0/lib/selenium/webdriver/remote/oss/bridge.rb:549:in `find_element_by'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.6.0/lib/selenium/webdriver/common/search_context.rb:62:in `find_element'
from (irb):60
from C:/Ruby23-x64/bin/irb.cmd:19:in `<main>'
、誰かがこのコードを修正するか、テキスト値を取得するための別の方法を提案することができますしてください?
ありがとうございました。
誤って別のXPathの出力を投稿して修正しました。 –