[英]Unable to find “Button” with Selenium in C#
I have got a problem with Selenium code to find a button which has only "Value"
and "type"
, in inspection it looks like this:我在使用 Selenium 代码时遇到了一个问题,无法找到一个只有"Value"
和"type"
的按钮,经过检查,它看起来像这样:
<input type="sumbit" value="login" />
I tried twice but neither line worked for me.我试了两次,但两条线都不适合我。
The lines:线路:
1st solution:第一个解决方案:
driver.FindElement(By.XPath("//button[contains(text(),'Login')]")).Click();
2nd solution:第二种解决方案:
driver.FindElement(By.ClassName("submit")).Click();
Image with ERROR MESSAGE (second line error)带有错误消息的图像(第二行错误)
Can anybody help me, or at least point out what am I missing, because its getting pretty frustrating to find a solution for such common thing, I practiced this on tutorial pages and buttons were never a problem.任何人都可以帮助我,或者至少指出我缺少什么,因为为这种常见的事情找到解决方案变得非常令人沮丧,我在教程页面上练习过,按钮从来没有问题。
Please.请。 (Sorry for my English) (对不起我的英语不好)
Ps: I checked the "similar questions and I haven't found the solution. Ps:我查了“类似的问题,我还没有找到解决方案。
Pss: Guys, there is another one which I didnt try yet but I have 3 different lines of code, do you think one of them will work: Pss:伙计们,还有另一种我还没有尝试过,但我有 3 行不同的代码,你认为其中一种会起作用吗:
There is drop-down list and I want to select the last thing in the list...有下拉列表,我想选择列表中的最后一件事......
driver.FindElement(By.XPath("//*[contains(., 'Process Data >>')]")); driver.FindElement(By.XPath("///*[contains(., '处理数据>>')]"));
driver.FindElement(By.Id("pdatasub")).Click(); driver.FindElement(By.Id("pdatasub")).Click();
driver.FindElement(By.XPath("//div[text()='Process Data >>']")).Click(); driver.FindElement(By.XPath("//div[text()='Process Data >>']")).Click();
Inspection of the Drop-down list检查下拉列表
Code for the opening of the last "button" in the drop-down list:打开下拉列表中最后一个“按钮”的代码:
driver.FindElement(By.XPath("//div[text()='Final Values']")).Click(); driver.FindElement(By.XPath("//div[text()='Final Values']")).Click();
enter link description here在此处输入链接描述
Thanks guys for help !谢谢你们的帮助!
Your locator is wrong.您的定位器有误。
You can use this:你可以使用这个:
driver.FindElement(By.XPath("//button[@type='submit']")).Click();
or要么
driver.FindElement(By.XPath("//button[@value='login']")).Click();
or要么
driver.FindElement(By.XPath("//button[@value='login' and @type='submit']")).Click();
CSS Selector can be used as well similarly. CSS Selector 也可以类似地使用。
Also there are several possible issues:还有几个可能的问题:
You are using the wrong locator :您使用了错误的定位器:
try this instead :试试这个:
driver.FindElement(By.XPath("//input[@type='submit' and @value='Login']")).Click();
or要么
With ExplicitWaits
使用ExplicitWaits
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@type='submit' and @value='Login']"))).Click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.