简体   繁体   English

Selenium Webdriver,单击按钮不起作用

[英]Selenium Webdriver, clicking a button not working

I am having two issues in clicking two buttons during my automation 我在自动化过程中点击两个按钮有两个问题

First : A View button which have the following Details 第一个: “视图”按钮,其中包含以下详细信息

<button class="veiw-btn" data-toggle="collapse" data-target=".toggle-content1" aria-expanded="false" aria-controls="toggle-content1" ng-click="gotoAnchor(flightResult.FlightId)">VIEW</button>

There are several VIEW buttons on the page but they are differentiated with the toggle-content (they have numbers 1,2,3,4) I just need to select the first one and click on it 页面上有几个VIEW按钮,但它们与toggle-content有区别(它们有数字1,2,3,4)我只需要选择第一个并点击它

Second : 第二:

After clicking the View i want to also click the Continue Button with the following code 单击“我想要查看”后,还可以使用以下代码单击“继续”按钮

<div class="text-center">
    <button class="flight-book-btn" type="button" ng-click="select(false, flightResult);">
     <span>Continue</span>
     </button>
</div>

My Major issue is the First Code but if i can get help with both i will be glad . 我的主要问题是第一个代码,但如果我能得到两者的帮助,我会很高兴。 I have not been able to click on the First VIEW Button 我无法点击第一个视图按钮

i have tried some samples online but they have not worked for me 我在网上尝试了一些样品,但他们没有为我工作

I expect to be able to click the VIEW and Continue Buttons 我希望能够单击VIEW和Continue Buttons

CODE: 码:

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);     
log.debug("Fastest Sort Available "); 
log.debug("Now about to click VIEW Airline Details "); 
// driver.findElement(By.xpath("//button[text()='VIEW' and @data-target='.toggle-content1' and @aria-controls='toggle-content1']")).click();; 
driver.findElement(By.cssSelector("button[class=\"veiw-btn\"][data-target='.toggle-content1'']")).click();

Try using the css selector or Xpath 尝试使用css选择器或Xpath

CSS: CSS:

driver.FindElement(By.CssSelector("button[class="veiw-btn"][data-target='.toggle-content1']").Click();

xpath: XPath的:

driver.FindElement(By.XPath("//button[@class='veiw-btn'][@data-target='.toggle-content1']").Click();

You can use this xpath to click on VIEW button : 您可以使用此xpath单击VIEW按钮:

//button[text()='VIEW' and @data-target='.toggle-content1' and @aria-controls='toggle-content1']

For clicking on Continue button you can try with this xpath : 要单击“继续”按钮,您可以尝试使用此xpath:

//span[text()='Continue']/parent::button[@class='flight-book-btn']

I have fixed this by using this 我用这个修好了

WebElement element= driver.findElement(By.xpath("//button[text()='VIEW' and @data-target='.toggle-content1' and @aria-controls='toggle-content1']")); WebElement element = driver.findElement(By.xpath(“// button [text()='VIEW'和@ data-target ='。toggle-content1'和@ aria-controls ='toggle-content1']”)) ;
JavascriptExecutor executor = (JavascriptExecutor) driver; JavascriptExecutor executor =(JavascriptExecutor)驱动程序; executor.executeScript("arguments[0].click();", element); executor.executeScript(“arguments [0] .click();”,element);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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