硒点击相应的文字一个JavaScript按钮 [英] Selenium to click on a javascript button corresponding to a text

查看:127
本文介绍了硒点击相应的文字一个JavaScript按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网页上有很多按钮,也是javascript按钮。所有这些按钮具有相同的TagName,但不同的ID。但我不能使用ID,因为我无法预测哪个按钮必须点击。





Selenium将搜索内容(问题这里),如果可以找到内容,那么它必须点击相应的按钮。

解决方案



任何意见都将非常有用, / div>

这将根据按钮上显示的文本找到一个按钮,然后点击它。

  var loggout = driver.FindElement(By.LinkText(Logg ut)); 
loggout.Click();

或者您可以将其更改为

  By.Id()
By.CssSelector()
By.Name()
...


I have a lot of buttons in my web page and that too are javascript buttons. All those buttons have same TagName, but different id. But I cant use ID since I cant predict which button has to be clicked.

Selenium will search for a content (Question here) and if could find the content, then it must click on the respective button. How can it be achieved?

Any comments would be really helpful and appreciated..

解决方案

This will find a button based on the displayed text on the button and click it.

var loggout = driver.FindElement(By.LinkText("Logg ut"));
loggout.Click();

Or you can change it to;

By.Id()
By.CssSelector()
By.Name()
...

这篇关于硒点击相应的文字一个JavaScript按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆