在Moneycontrol的登录页面中,Selenium无法找到Webelementes

在Moneycontrol的website中,我无法在尝试登录时输入用户名和密码。Selenium无法找到Webelement。在Moneycontrol的登录页面中,Selenium无法找到Webelementes

public void setUrl() throws IOException { 

driver = new FirefoxDriver()

driver.get("http://www.moneycontrol.com/");

}

public void Login() {

driver.findElement(By.xpath("//a[@title='Log In']")).click();

//enter user name and password

driver.findElement(By.xpath("//div[@class='formbox']/div[1]/form/div[1]")).sendKeys("[email protected]");

driver.findElement(By.xpath("//input[@id='pwd']")).sendKeys("[email protected]");

screenshot

回答:

Email or User ID字段是一个内,所以在Email or User IDPassword字段调用sendKeys()必须切换到相应如下:

new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@src='https://accounts.moneycontrol.com/mclogin/?d=2']"))); 

driver.findElement(By.xpath("//form[@id='login_form']//input[@class='textfield' and @id='email']")).sendKeys("[email protected]");

driver.findElement(By.xpath("//form[@id='login_form']//input[@class='textfield' and @id='pwd']")).sendKeys("[email protected]");

回答:

**Selenium with C#** 

你需要切换到框架,在你的情况下,你的框架ID是“myframe”。以下是使用C#编写硒的工作代码:

[TestMethod] 

public void moneyControl()

{

IWebDriver driver = new ChromeDriver(@"C:\Users\Akash\Downloads\chromedriver_win32\");

driver.Navigate().GoToUrl("http://www.moneycontrol.com/");

driver.Manage().Window.Maximize();

driver.FindElement(By.XPath("//a[@title='Log In']")).Click();

driver.SwitchTo().Frame("myframe");

driver.FindElement(By.Id("email")).SendKeys("[email protected]");

driver.FindElement(By.Id("pwd")).SendKeys("abc");

}

以上是 在Moneycontrol的登录页面中,Selenium无法找到Webelementes 的全部内容, 来源链接: utcz.com/qa/266057.html

回到顶部