【问题标题】:How to select the international telephone input with flags and dial codes dropdown in selenium如何在 selenium 中选择带有标志和拨号代码下拉列表的国际电话输入
【发布时间】:2021-04-18 18:07:06
【问题描述】:

this website 如何在 selenium 中为手机字段选择带有标志和拨号代码下拉列表的国际电话输入。硒代码没有选择

我写的代码。

<div class="control-group ">
    <label class="control-label required" for="CellPhone">Cell Phone</label>
    <div class="controls">
      <input class="form-control phone-number" data-val="true" data-val-intltel="Invalid number" data-val-required="The Cell Phone field is required." id="CellPhone" name="CellPhone" type="text" value="" />
      <span class="help-block">
        <span class="field-validation-valid" data-valmsg-for="CellPhone" data-valmsg-replace="true"></span>
      </span>
    </div>
  </div>


package testing123;





import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;


public class dancekarwebsite1 {
    


    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\Vpatiballa\\Desktop\\Lib\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://dancekar.com/parent-center/register");
        driver.manage().window().maximize();
        
        //*[@id="Email"]
        
        //Actions actions = new Actions(driver);

          // Scroll Down using Actions class
         // actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("window.scrollBy(0,250)", "");
        
    //driver.findElement(By.xpath("//div[@class='selected-flag']")).click();
        
    
    
    
    Actions action = new Actions(driver);    
    WebElement optionsList = driver.findElement(By.xpath("//div[@class='selected-flag']"));
    action.moveToElement(optionsList);

    List<WebElement> options = driver.findElements(By.xpath("//div[@class='selected-flag']"));
    for(WebElement option : options) {
        if (option.getText().equals("United Kingdom +44")) {
            option.click();
        }
    }
    
    
    
    
    
    
    
    
    }
    }

     

【问题讨论】:

  • 您的问题解决了吗?

标签: selenium dropdown


【解决方案1】:
  1. 您应该单击您的标志以打开下拉菜单,您使用 action.moveToElement 但这不会执行点击,也不会打开下拉菜单。试试:

    action.moveToElement(optionsList).build().perform();
    
  2. 您可能需要等到下拉菜单打开。

  3. 要获取元素列表,请使用:

    List<WebElement> options = driver.findElements(By.cssSelector(".country .country-name"));
    

【讨论】:

    猜你喜欢
    • 2015-07-15
    • 2019-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多