Edge Webdriver:在标签文本中添加了空格

时间:2019-06-24 22:31:28

标签: selenium webdriver microsoft-edge

Edge webdriver:为标签文本添加空格。例如

<input type='radio' id="myid" name="hello" value="1">
<label for="myid">SomeText</label>

WebElement labelElement = ...
labelElement.getText();  // returned value has a space before SomeText

1 个答案:

答案 0 :(得分:1)

下面的代码在MS Edge上正常工作,可以正确获取标签文本,而无需任何额外空间。

C#代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {

            IWebDriver driver = new EdgeDriver();

            driver.Navigate().GoToUrl(@"C:\Users\panchals\Desktop\tests\test1.html");

            try
            {           
                Console.WriteLine(driver.FindElement(By.XPath("//label[@for='myid']")).Text);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
            driver.Quit();
            driver.Close();

        }
    }
}

HTML代码:

<input type='radio' id="myid" name="hello" value="1">
<label for="myid">SomeText</label>

输出:

enter image description here

我还建议您在上一个主题中将有用的建议标记为答案,或者尝试更新问题的状态。

webdriver edge: dispatchEvent for input element not working