Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winforms 如何使用SeleniumWebDriver获取处于选定模式的文本的元素id?_Winforms_Selenium_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

Winforms 如何使用SeleniumWebDriver获取处于选定模式的文本的元素id?

Winforms 如何使用SeleniumWebDriver获取处于选定模式的文本的元素id?,winforms,selenium,selenium-webdriver,selenium-chromedriver,Winforms,Selenium,Selenium Webdriver,Selenium Chromedriver,网站中有多个id,但我想使用SeleniumWebDriver获取处于选定模式的文本的id 从下面的代码,我如何才能得到唯一的id是“颜色” 挑选 红色 蓝色 谢谢 <i> WebElement Cct; cct = driver.findElement(By.id("Colour"); String blue = blue.getAttribute("value"); Assert.assertEquals(value, "Blue"); </i> 网络元素Cc

网站中有多个id,但我想使用SeleniumWebDriver获取处于选定模式的文本的id

从下面的代码,我如何才能得到唯一的id是“颜色”


挑选
红色
蓝色
谢谢


<i>
WebElement Cct; 
cct = driver.findElement(By.id("Colour");
String blue = blue.getAttribute("value");
Assert.assertEquals(value, "Blue");
</i>
网络元素Cct; cct=驾驶员识别号(“颜色”); 字符串blue=blue.getAttribute(“值”); Assert.assertEquals(值,“蓝色”);
我们可以通过为特定的
td
选择
属性来获取
id
属性。请尝试下面的代码

String requiredId = driver.FindElement(By.XPath("//option[@selected='selected']/..")).GetAttribute("id");
基于颜色名称(不推荐,因为可以选择不同的颜色)


您的代码试用版?String gettingid=this.driver.FindElement(By.XPath(“/*[contains(text(),'Blue')]]/option[@selected]”)。GetAttribute(“id”);所选选项
Blue
没有任何id属性。不,它只有value属性。我们需要蓝色处于所选模式的部分的id。请帮助我@DebanjanBWe有数百个id。你需要单击此元素还是什么?每当蓝色处于选择模式时,我需要所有id。@Old_The_jackal我怎么能ass string
getcolor
取代蓝色?@muzzamil你能在这里告诉我答案吗:@Muzzamil@rajeshparipelly试试那个链接。嗨,兄弟,你能在这里告诉我这个答案吗:@Muzzamilhi兄弟,你能帮我解决这个问题吗:@Muzzamil
String requiredId = driver.FindElement(By.XPath("//option[@selected='selected']/..")).GetAttribute("id");
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(45));
IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//option[@selected='selected' and .='Blue']/..")));

    String requiredId = element.GetAttribute("id");