即使没有重复的类名,我的代码也无法在Nordstrom机架网站上找到元素。元素帐户(注册后)无法识别。
using NordstromRack.UI_Elements;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Support.UI;
using System;
using System.Threading;
namespace NordstromRack
{
class EntryPoint
{
static void Main(string[] args)
{
String parentHandle = Driver.driver.CurrentWindowHandle; // get the current window handle
EmailSignUp signup = new EmailSignUp();
ProfileUpdate profile = new ProfileUpdate();
Driver.driver.Navigate().GoToUrl("https://www.nordstromrack.com/");
Driver.driver.Manage().Window.Maximize();
Thread.Sleep(1000);
signup.SignUpLink.Click();
foreach (String winHandle in Driver.driver.WindowHandles)
{
Driver.driver.SwitchTo().Window(winHandle);
}
//WebDriverWait wait = new WebDriverWait(Driver.driver, TimeSpan.FromSeconds(1000));
//wait.Until(ExpectedConditions.ElementToBeClickable(signup.EmailInput));
signup.EmailInput.Click();
signup.EmailInput.SendKeys(Config.Credentials.Valid.BaseEmail);
Thread.Sleep(1000);
signup.Password.Click();
signup.Password.SendKeys(Config.Credentials.Valid.Password);
Thread.Sleep(1000);
signup.Password.Submit();
//signup.SignOut.Click();
//WebDriverWait wait = new WebDriverWait(Driver.driver, TimeSpan.FromSeconds(1000));
//wait.Until(ExpectedConditions.ElementToBeClickable(profile.Account));
Thread.Sleep(2000);
Driver.driver.SwitchTo().Window(parentHandle);
Thread.Sleep(2000);
profile.Account.Click();**//Unable to locate this element**
Thread.Sleep(5000);
//Driver.driver.Quit();
}
}
}
Profile.cs类详细信息,其中包含帐户元素的定位器详细信息。我究竟做错了什么? 引发的错误:无法通过以下方式找到元素:By.CssSelector:secondary-nav__link.secondary-nav__link--帐户
using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;
namespace NordstromRack.UI_Elements
{
public class ProfileUpdate
{
public ProfileUpdate()
{
PageFactory.InitElements(Driver.driver, this);
}
[FindsBy(How = How.CssSelector, Using = "input.form-label__input.form-label__input--password")]
public IWebElement Profile { get; set; }
[FindsBy(How = How.CssSelector, Using = "secondary-nav__link.secondary-nav__link--account")]
public IWebElement Account { get; set; }
}
}
答案 0 :(得分:1)
使用Css Sector时,不必提供完整的类名。您可以输入tagname.any of the class attribute
或.any of the class attribute
相反,
"secondary-nav__link.secondary-nav__link--account"
您可以尝试将其用作CSS选择器
WebElement element1=driver.findElement(By.cssSelector("a.secondary-nav__link"));
Actions action = new Actions(driver);
action.moveToElement(element1).click().build().perform();;