Tôi đang thử nghiệm web của mình bằng cách chọn một tùy chọn. Bạn có thể tìm thấy ví dụ tại đây: http://www.tizag.com/phpT/examples/formex.phpLàm thế nào để chọn một tùy chọn từ trình đơn thả xuống bằng Selenium WebDriver C#?
Mọi thứ đều hoạt động tốt ngoại trừ việc chọn phần tùy chọn. Cách chọn tùy chọn theo giá trị hoặc theo nhãn?
Mã của tôi:
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;
class GoogleSuggest
{
static void Main()
{
IWebDriver driver = new FirefoxDriver();
//Notice navigation is slightly different than the Java version
//This is because 'get' is a keyword in C#
driver.Navigate().GoToUrl("http://www.tizag.com/phpT/examples/formex.php");
IWebElement query = driver.FindElement(By.Name("Fname"));
query.SendKeys("John");
driver.FindElement(By.Name("Lname")).SendKeys("Doe");
driver.FindElement(By.XPath("//input[@name='gender' and @value='Male']")).Click();
driver.FindElement(By.XPath("//input[@name='food[]' and @value='Chicken']")).Click();
driver.FindElement(By.Name("quote")).Clear();
driver.FindElement(By.Name("quote")).SendKeys("Be Present!");
driver.FindElement(By.Name("education")).SendKeys(Keys.Down + Keys.Enter); // working but that's not what i was looking for
// driver.FindElement(By.XPath("//option[@value='HighSchool']")).Click(); not working
// driver.FindElement(By.XPath("/html/body/table[2]/tbody/tr/td[2]/table/tbody/tr/td/div[5]/form/select/option[2]")).Click(); not working
// driver.FindElement(By.XPath("id('examp')/x:form/x:select[1]/x:option[2]")).Click(); not working
}
}
công trình như một say mê cảm ơn! làm cho mọi việc nhanh hơn cho các bài kiểm tra của tôi! – motto
Có lỗi. 'var selectElement = new SelectElement (giáo dục);' Nên là: 'var selectElement = new SelectElement (phần tử);' –
@greg thanks, cố định rằng –