我想点击一个按钮,让我把它带到一个页面,然后我就会得到它的Url。之后,它必须单击单选按钮和同一页面上的按钮。单击工作正常,但正如您在代码中看到的那样,它处于for循环中。这就是为什么它不等待Web浏览器导航。它继续前进并完成循环。
我已经尝试过Timer但计时器没有做滴答工作。我怎么能这样做?
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(xmlPath);
List<string> ListSs = new List<string>();
XmlNodeList ilValuesList = xmldoc.SelectNodes("//*[@class='il']");
List<string> ilLinkList = new List<string>();
int sayac = 1;
for (int i = 0; i < kategoriler.Length; i++)
{
foreach (XmlNode item in ilValuesList)
{
string ilAdi = item.Name;
string ilValue = item.Attributes["value"].Value;
foreach (HtmlElement hElement in webBrowser1.Document.GetElementsByTagName("input"))
{
if(hElement.GetAttribute("value").Equals(ilValue))
{
hElement.InvokeMember("click");
break;
}
}
foreach (HtmlElement hElementButton in webBrowser1.Document.GetElementsByTagName("a"))
{
if (hElementButton.GetAttribute("id").Equals("btnSearch"))
{
hElementButton.InvokeMember("click");
break;
}
}
ListSs.Add(webBrowser1.Url.ToString());
}
for (int j = 0; j < ListSs.Count; j++)
{
string xPath = Application.StartupPath + "\\XMLDosyalari" + kategoriXml[i];
XDocument xdoc = XDocument.Load(xPath);
xdoc.Element("Hepsi").Add(new XElement(ilValuesList[j].Name, new XAttribute("value", ilValuesList[j].Attributes["value"].Value), new XAttribute("url", webBrowser1.Url.ToString())));
xdoc.Save(xPath);
}
答案 0 :(得分:0)
我解决了它,如果你不能像我这样做,你可以试试这个;
private void il_url_btn_Click(object sender, EventArgs e)
{
foreach (HtmlElement item in webBrowser1.Document.GetElementsByTagName("input"))
{
if (item.GetAttribute("value").Equals(IlValuesList[sayac].Attributes["value"].Value))
{
item.InvokeMember("click");
break;
}
}
foreach (HtmlElement item in webBrowser1.Document.GetElementsByTagName("a"))
{
if (item.GetAttribute("id").Equals("btnSearch"))
{
item.InvokeMember("click");
break;
}
}
linkCek = true;
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (linkCek)
{
if (e.Url == webBrowser1.Url)
{
if (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
return;
else
{
string path = Application.StartupPath + "\\XMLDosyalari" + kategoriXml[0];
XDocument xdoc = XDocument.Load(path);
xdoc.Element("Hepsi").Add(new XElement(IlValuesList[sayac].Name, new XAttribute("class", "il"), new XAttribute("value", IlValuesList[sayac].Attributes["value"].Value), new XAttribute("url", webBrowser1.Url.ToString())));
xdoc.Save(path);
sayac++;
il_url_btn.PerformClick();
}
}
else { return; }
}
else { }
}