简体   繁体   English

无法在Selenium WebDriver中单击按钮

[英]Not able to click on a button in selenium webdriver

webDriver driver = new FirefoxDriver();
driver.get("https://www.ignitionone.com/company/careers/");
driver.manage().window().maximize();        
Thread.sleep(2000);

driver.findElement(By.xpath("html/body/div[1]/section[1]/div/div/a/button")).submit();

'View positions' button is not clicking with the above code.What is happening in the web page? 没有使用上面的代码单击“查看位置”按钮。网页中发生了什么?

You see the HTML for this page is 您看到此页面的HTML是

的HTML

So, you can use the CSS selector for this as 因此,您可以为此使用CSS选择器

WebDriver driver = new FirefoxDriver();
driver.get("https://www.ignitionone.com/company/careers/");
driver.manage().window().maximize();        
Thread.sleep(2000);

driver.findElement(By.cssSelector("button.button.teal").click();

And then proceed with doing whatever is necessary. 然后继续进行必要的操作。 I executed with this in my Python code and it works fine. 我在我的Python代码中执行了此命令,并且工作正常。

Also, you will need to provide the Gecko executable path while calling for the FirefoxDriver() 另外,在调用FirefoxDriver() ,需要提供Gecko可执行文件路径。

The way I have done it before is to use the click handler. 我之前做过的方法是使用点击处理程序。

driver.findElement(By.cssSelector(".profile-actions .primary_button > span")).click();

I'm sure you could also select the element by xpath rather than CSS in the above line. 我确定您也可以通过xpath而不是CSS在上一行中选择元素。 It's a similar question to this one . 这个问题与类似。

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

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