using Selenium webdriver to find elements with  

前端 未结 3 1910
遥遥无期
遥遥无期 2021-01-16 22:50

Hope you\'re all well. I\'m quite new to selenium and a complete newbie to stack overflowso i hope i\'m not disobeying any rules here.

I am trying to create a test f

相关标签:
3条回答
  • 2021-01-16 23:17
    IWebElement element = driver.FindElement(By.XPath("//span[contains(@class'com') and normalize-space(translate(., '\u00A0', ' '))='Alumina MB China metallurgical grade delivered']"));
    

    Explanation: Use xpath to find a span element with class containing the string com, get the text from that (.) replace all of the &nbsp characters (i.e. unicode \u00A0) with a regular space character, and strip leading and trailing whitespace (this last part may not be needed in your situation).

    Note: the string that should go in the single quotes after the = should only contain regular spaces.

    0 讨论(0)
  • 2021-01-16 23:22

    Try to escape html characters by using System.Web.HttpUtility.HtmlDecode

    it works for me:

    var escaped = System.Web.HttpUtility.HtmlDecode(".//span[text()='Alumina MB China metallurgical grade delivered duty paid RBM/tonne']");
    IWebElement element = driver.FindElement(By.XPath(escaped));
    
    0 讨论(0)
  • 2021-01-16 23:35

    you should first replace all instances of $nbsp; in your xpath string to and then search for that

    0 讨论(0)
提交回复
热议问题