简体   繁体   中英

How to click on an list element within ol using Selenium and C#

I am working with C# selenium as an amateur. How can I select the country on the site below. I tried many things but I couldn't choose.

Url: " https://support.google.com/legal/contact/lr_counternotice?product=websearch "

Snapshot of the element:

在此处输入图像描述

To click on the <li> element with text Afghanistan you have to induce WebDriverWait for the ElementToBeClickable() and you can use either of the following Locator Strategies :

  • CssSelector :

     new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("div.sc-select[aria-label^='Country of residence']"))).Click(); new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("ol.sc-select-show li[id=':2']"))).Click();
  • XPath :

     new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[@class='sc-select' and starts-with(@aria-label, 'Country of residence')]"))).Click(); new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//ol[@class='sc-select-show']//li[text()='Afghanistan']"))).Click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM