简体   繁体   English

如何通过Selenium和C#根据给定的HTML单击元素

[英]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.

相关问题 如何通过Selenium和C#根据HTML在模态对话框中单击文本为“关闭”的按钮 - How to click on the button with text as Close within a modal dialog box as per the html through Selenium and C# 如何通过Selenium和C#按HTML上的公共文本单击按钮 - How to click on the button with text as public as per the HTML through Selenium and C# 如何通过Selenium和C#在HTML中定位元素 - How to locate the element within the HTML through Selenium and C# 如何使用 Selenium 和 C# 通过元素 ID 属性单击单选按钮 - How to click on the radio button through the element ID attribute using Selenium and C# 如何使用 Webdriver 和 C# 通过 Selenium 定位并单击嵌套在多个框架和框架集中的元素 - How to locate and click on an element which is nested within multiple frame and frameset through Selenium using Webdriver and C# 如何使用 Selenium 和 C# 单击此特定元素 - How to click on this specific element using Selenium and C# 如何通过C#单击Selenium Webdriver中的DOM元素 - How to click the DOM element in selenium webdriver thru C# 如何在 c# Selenium 中找到 reCAPTCHA 元素并单击它 - How to Find the reCAPTCHA element and click on it in c# Selenium 如何使用 Selenium 和 C# 在 ol 中单击列表元素 - How to click on an list element within ol using Selenium and C# 如何通过Selenium和C#对输入元素调用SendKeys() - How to invoke SendKeys() to the input element through Selenium and C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM