Ich habe Seite mit vielen Dropdown-Menüs und ich habe ein Problem beim Schreiben etwas generisches anstelle von Hardcoding den vollständigen Pfad.Partial Match Wählen Sie ein Element in Dropdown C#
Die Idee ist, das Land Drop-Down-und Auswählen eines Elements aus der Dropdown-
Das funktioniert
public MyPage WithCountry(string countryValue)
{
driver
.FindElement(By.CssSelector("#ctl00_MainContentPlaceholder_ApplicantDetails1_Panel_ctl00_ctl03_CountryList > span.ui-selectmenu-text"))
.Click();
driver.FindElement(By.Id("ui-id-162")).Click();
return this;
}
Das funktioniert nicht
public MyPage WithCountry(string countryValue)
{
var element=driver.FindElement(By.CssSelector("[Id$=ctl03_CountryList]");
element(By.CssSelector("# > span.ui-selectmenu-text")).Click(); //NOT SURE ABOUT THIS GIVES ME ERROR.
driver.FindElement(By.Name(countryValue)).Click();
return this;
}
html
zu lokalisieren<ul id="ctl00_MainContentPlaceholder_ucApplicantDetails1_ApplicantPanel_ctl00_ctl03_CountryList" class="form-columns">
<li class="large-4 columns">
<label for="ctl00_MainContentPlaceholder_ucApplicantDetails1_ApplicantPanel_ctl00_ctl03CountryListList" id="ctl00_MainContentPlaceholder_ucApplicantDetails1_ApplicantPanel_ctl00_ctl03_CountryListLblFor">CountryList
<span class="req">*</span>
</label>
</li>
<li class="hidden">
<span id="ctl00_MainContentPlaceholder_ucApplicantDetails1_ApplicantPanel_ctl00_ctl03_CountryListReqVal" style="color:Red;display:none;"></span>
</li>
<li class="large-12 columns">
<select name="ctl00$MainContentPlaceholder$ucApplicantDetails1$ApplicantPanel$ctl00$ctl03$CountryList" id="ctl00_MainContentPlaceholder_ucApplicantDetails1_ApplicantPanel_ctl00_ctl03_CountryList" class="xxx">
<option selected="selected" value=""></option>
<option value="Spain">Spain</option>
Kann jemand irgendwelche Vorschläge geben, wie ich diese Methode Code sollte so, dass ein Element in der Dropdown ausgewählt wird, indem das Element durch partielle Übereinstimmung gefunden
zeigen 'HTML'-Code für die gleiche – Andersson
hinzugefügt html, das betrifft diesen Drop-down – developer9969
Was meinst du eigentlich teilweise übereinstimmen ?? Möchten Sie eine Option aus Dropdown mit teilweisem Text auswählen? –