Ruby Selenium Web Drive: How to find specific element by xpath div id and css class

后端 未结 3 401
北海茫月
北海茫月 2021-01-27 22:45

I have a below html which am trying to test using ruby selenium web driver

3条回答
  •  一整个雨季
    2021-01-27 23:20

    According to the Selenium documentation :css is not a valid selector for find_elements.

    It specified :class, :class_name, :id, :link_text, :link, :partial_link_text, :name, :tag_name, :xpath to be valid selectors.

    The :css selector do still work in many situations, however it does not always work as you would expect. For example would div.container-fluid.container-results > div#0 be invalid for selenium, even tho it is valid for the browsers.

    You could use xpath or some of the other selectors to get the svg.

    If you want to use the css selector to find it, you could use nokogiri, here is an example:

    selenium_driver = Selenium::WebDriver.for :chrome
    selenium_driver.get("http://stackoverflow.com/")
    
    # do whatever with selenium
    
    doc = Nokogiri::HTML(selenium_driver.page_source)
    doc.css("div.container-fluid.container-results >div##{row_number.to_i-1} >ul >li >a >svg")
    

提交回复
热议问题