C# için Selenyum Webdriver uygulamasında MoveToElement işleviyle ilgili sorunlar. MoveToElement bir şey yapmıyor gibi görünüyor. Navigasyon maddelik fare tarafından üzerinde süpürdü kadarSelenyum MoveToElement öğesi XPath tarafından bulunamadıysa çalışmaz.
<div id="rounded-navigation-with-icons">
<ul>
<li class="navigation-item">
<a href="Members" target="_self" class="navigation-item-title"></a>
<ul>
<li>
<a href="MembersTestPage" target="_self"></a>
</li>
</ul>
</li>
</ul>
</div>
en iç liste başlangıçta gizli:
Aşağıdaki HTML var.
Daha sonra Selenium'da görünen gezinme öğesi başlıklarını tıklatıp aşağıdakileri yapın ve sonra MembersTestPage bağlantısını tıklatın.
public bool SearchForElement(string elementToFind, Page.FindBy by)
{
var navigation = Page.FindElement("rounded-navigation-with-icons", Page.FindBy.ID);
if (navigation != null)
{
foreach (var item in navigation.FindElements(By.ClassName("navigation-item")))
{
var titleElements = Page.FindElements("navigation-item-title", Page.FindBy.ClassName);
Actions action = new Actions(Driver.Instance);
foreach (var moveToItem in titleElements)
{
try
{
// Move to the main navigation link container element, but it doesn't work
action.MoveToElement(moveToItem);
// Move the mouse position manually to the link's location
action.MoveByOffset(moveToItem.Location.X, moveToItem.Location.Y);
// This does correctly find the element
var element = Page.FindElement("a[href='MembersTestPage']", Page.FindBy.CssSelector);
action.MoveToElement(element);
// Click returns that the element is hidden/invisible and therefore cannot be clicked
element.Click();
return true;
}
catch (Exception)
{
}
}
}
}
return false;
}
Benim öğe geçirerek moveToElement kullanılan ve el ile de X ve öğenin Y değerlerini geçirerek, ama ikisi de çalışıyoruz gelmiş görebilirsiniz.
Öğeleri XPath tarafından bulursam, beklendiği gibi çalışır.
Neyi yanlış yapıyorum? Teşekkür
Bu mükemmel bir şekilde çalıştı. Çok basit olduğuna inanamıyorum, teşekkürler! – youyong