简体   繁体   中英

How to click on the element as per the given HTML through Selenium and C#

I want to send instagram shipment with mobile imitation. 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.

Relevant 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM