[英]How to click on the element as per the given HTML through Selenium and C#
I want to send instagram shipment with mobile imitation. 我想通过移动设备发送instagram货件。 but I need to click on a button for the new shipment.
但是我需要单击一个按钮以发送新货。 I tried everything about button click but I did not manage it.
我尝试了有关按钮单击的所有操作,但没有进行管理。
public static void HoverMouseOverClicks(IWebElement element)
{
Actions action = new Actions(insta);
action.MoveToElement(element);
IJavaScriptExecutor executor = (IJavaScriptExecutor)insta;
executor.ExecuteScript("arguments[0].scrollIntoView(true);arguments[0].click();", element);
}
code click-through code you've seen above 您在上面看到的代码点击代码
HoverMouseOverClicks(insta.FindElement(By.XPath("//*[@id='react-root']/section/nav[2]/div/div/div[2]/div/div/div[3]/span")));
I try this and I still can not get the result. 我尝试这样做,但仍然无法获得结果。
insta.FindElement(By.XPath("//*[@id='react-root']/section/nav[2]/div/div/div[2]/div/div/div[3]/span")).Click();
This code sometimes clicks and sometimes does not click. 此代码有时单击,有时不单击。
The XPath path never changes. XPath路径永不更改。
Relevant HTML: 相关HTML:
<div class="q02Nz _0TPg" role="menuitem"><span class="glyphsSpriteNew_post__outline__24__grey_9 Szr5J">Yeni Gönderi</span> <span class="glyphsSpriteNew_post__outline__24__grey_9 Szr5J">Yeni Gönderi</span></div>
what should I do? 我该怎么办?
根据您共享的HTML,单击带有YeniGönderi的文本的元素,您需要诱使WebDriverWait使该元素可单击,并且可以使用以下解决方案:
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[@role='menuitem']//span[contains(@class, 'glyphsSpriteNew_post__') and contains(.,'Yeni Gönderi')]"))).Click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.