我的代码是:
driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.truereligion.com/");
driver.findElement(By.id("Header1_wcLocalization_imgShippingCountryFlag")).click();
driver.switchTo().frame("__cvo_iframe");
WebDriverWait wait=new WebDriverWait(driver, 10);
WebElement element=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("html/body/form[1]/div[2]/div[2]/div[1]/div[1]/div[4]/div[2]/input")));
element.click();
driver.close();
获取例外:
org.openqa.selenium.remote.ErrorHandler$UnknownServerException:
Unable to locate element :
{ "method": "xpath",
"selector": "html/body/form[1]/div[2]/div[2]/div[1]/div[1]/div[4]/div[2]/input"
}"
如何解决此问题?
答案 0 :(得分:0)
尝试点击这样:
WebElement element=wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ProceedAsUSuser")));
element.click();
答案 1 :(得分:0)
首先,“__cvo_iframe”错误的定位器我认为在点击'India& amp;以后“链接(但不确定)。无论如何,在工作C#代码下面点击链接,切换到框架并点击”ProceedAsUser“链接。如果需要在操作之间添加等待时间:
//Creates ChromeDriver
var driver = CreateBrowser("http://www.truereligion.com/");
driver.FindElement(By.CssSelector("#Header1_wcLocalization_lnkInternationalWebsite")).Click();
var frame = driver.FindElement(By.CssSelector(".iframeIntPop"));
driver.SwitchTo().Frame(frame);
driver.FindElement(By.CssSelector("#ProceedAsUSuser")).Click();
P.S。仅供参考,本网站不适用于FF(25 ver)。我在移动设备“http://m.truereligion.com/?l=US&c=USD”
中登录时显示的网站答案 2 :(得分:0)
您的代码出了什么问题:
iframeIntPop
)与您在代码中编写的框架ID(__cvo_iframe
)不同。Proceed as US user
的XPath也是错误的以下代码有效,
driver.get("http://www.truereligion.com/");
driver.findElement(By.cssSelector(" #header-secondary > div > ul")).click();
driver.findElement(By.id("Header1_wcLocalization_imgShippingCountryFlag")).click();
WebDriverWait wait=new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='_CHtmlForm1']/div[5]/iframe")));
WebElement frameID = driver.findElement(By.xpath("//*[@id='_CHtmlForm1']/div[5]/iframe"));
driver.switchTo().frame(frameID);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='ProceedAsUSuser']")));
WebElement element=driver.findElement(By.xpath("//*[@id='ProceedAsUSuser']"));