[英]Can't find element in webpage using selenium C#?
Can't find any element in the page have 2 iframes nested in selenium? 在页面中找不到任何元素将2个iframe嵌套在硒中吗?
When the first start, I find all element in the browser but when to go to iframe[0] I can't find any element in the browser. 第一次启动时,我在浏览器中找到了所有元素,但是当转到iframe [0]时,我在浏览器中找不到任何元素。
My code like: 我的代码如下:
var iframes = browser.FindElementsByXPathName("//iframe[contains(@id,'container_page')]");
while (browser.FindElementsByXPathName("//span[contains(@class, 'button_Love')]").Count == 0 && iframes.Count == 0)
Thread.Sleep(1000);
if (iframes.Count > 0)
{
browser.GoToFrame(iframes[0]);
Thread.Sleep(2000);
}
try following code. 尝试以下代码。
var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("you URL");
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
//check if there is any iframe then get that frame and switch on frame using folloiwng code.
var frame = wait.Until(ExpectedConditions.ElementExists(By.Id("frame_id")));
driver.SwitchTo().Frame(frame);
var elementbutton_Love = driver.FindElements(By.ClassName("button_Love"));
//after doing all work you can go to default content using following code
driver.SwitchTo().DefaultContent();
if any issue then let me know. 如果有任何问题,请通知我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.