C# 使用Selenium单击下拉按钮
我需要单击tweet中的下拉按钮,然后使用SeleniumWeb驱动程序单击“嵌入tweet”选项 我在网上找到了这些代码,并试图实现这些代码,但第三行代码不起作用:C# 使用Selenium单击下拉按钮,c#,selenium,C#,Selenium,我需要单击tweet中的下拉按钮,然后使用SeleniumWeb驱动程序单击“嵌入tweet”选项 我在网上找到了这些代码,并试图实现这些代码,但第三行代码不起作用: driver = new ChromeDriver(@"C:\ChromeDriver 75.0.3770.90"); driver.URL= "https://twitter.com/TheScaryNature/status/1170560743516692480"; driver.FindElement(By.XPath(
driver = new ChromeDriver(@"C:\ChromeDriver 75.0.3770.90");
driver.URL= "https://twitter.com/TheScaryNature/status/1170560743516692480";
driver.FindElement(By.XPath("//input[@id='']")).Click();
但它不起作用。我是初学者。请帮忙。可能有两个原因(据我所知):
IList<IWebElement> tooltip= driver.FindElements(By.XPath("//div[@class='IconContainer js-tooltip']/span[@class='Icon Icon--caretDownLight Icon--small']"));
tooltip.Click();
IList tooltip=driver.FindElements(By.XPath(“//div[@class='IconContainer js tooltip']]/span[@class='Icon-Icon-caretDownLight-Icon-small']);
工具提示。单击();
您可以通过以下代码选择按钮:-
driver.findelelement(By.xpath(“/*[@id='menu-0']”)。单击()
单击按钮后,您可以单击嵌入推文:-
driver.findelelement(By.xpath(“//button[contains(text(),'Embed Tweet')]”)。click();
By.xpath
用作css选择器。由于并非每个元素都有ID,而且在我看来,twitter上的下拉菜单似乎没有ID,所以您可以尝试使用
driver.findElement(By.XPath("//li[@class='embed-link']/button[@class='dropdown-link']"))
//li/按钮
表示li>按钮
(li元素内的按钮)
第一个等待元素出现 wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(//button[@id='menu-0']///span[@class='Icon-Icon--caretDownLight-Icon--small'])) 然后
driver.findElement(By.xpath(“//button[@id='menu-0']]///span[@class='Icon-Icon--caretDownLight-Icon--small'])。单击是否会收到任何错误消息?只说它不起作用会少一点…嗨@Daniel,谢谢你的回复。我收到消息-'没有这样的元素:找不到元素'嗨,我收到这个错误-找不到元素:{“方法”:“xpath”,“选择器”:”//li[@class='embed-link']/button[@class='dropdown-link']]“}您好,我收到了这个错误-'没有这样的元素:无法找到元素:{“方法”:“xpath”,“选择器”:“/*[@id='menu-0']”您好,请您分享元素详细信息,以便我验证。您是否检查了框架?您是否可以发布您正在尝试的网页的URL?
IList<IWebElement> tooltip= driver.FindElements(By.XPath("//div[@class='IconContainer js-tooltip']/span[@class='Icon Icon--caretDownLight Icon--small']"));
tooltip.Click();
driver.findElement(By.XPath("//li[@class='embed-link']/button[@class='dropdown-link']"))