![](/img/trans.png)
[英]Selenium - driver.find_element_by_css_selector can't find the element (c#)
[英]Can't find element in webpage using selenium C#?
在頁面中找不到任何元素將2個iframe嵌套在硒中嗎?
第一次啟動時,我在瀏覽器中找到了所有元素,但是當轉到iframe [0]時,我在瀏覽器中找不到任何元素。
我的代碼如下:
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);
}
嘗試以下代碼。
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();
如果有任何問題,請通知我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.