Selenium driver.getTitle() 不工作 [英] Selenium driver.getTitle() is not working
本文介绍了Selenium driver.getTitle() 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
driver.getTitle() 不返回页面的标题.它返回空值.我在网页中有以下 html 结构:
<!-- 需要翻译标题--><!-- gomez.jsp 需要--><script type="text/javascript" async="" src="https://ssl.google-analytics.com/ga.js"></script><script type="text/javascript">... </script><script src="https://B001E0.t.axf8.net/js/gtag5.js" type="text/javascript"></script><标题>应用很快....
有人能解释一下这里的问题吗..提前致谢
解决方案
那么你可能想要像下面这样显式等待:
<前>void waitForLoad(WebDriver 驱动程序){预期条件页面加载 = 新预期条件(){公共布尔应用(WebDriver 驱动程序){return (Boolean)((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");}};WebDriverWait wait = new WebDriverWait(driver, 30);等待.直到(页面加载);}然后您可以执行以下操作:
<前>驱动程序.getTitle()driver.getTitle() does not return the title of the page. It returns null. I have the below html structure in the web page:
<head>
<!-- needed for translation of titles -->
<!-- needed for gomez.jsp -->
<script type="text/javascript" async="" src="https://ssl.google-analytics.com/ga.js"> </script><script type="text/javascript"> … </script><script src="https://B001E0.t.axf8.net/js/gtag5.js" type="text/javascript"></script>
<title>
Applications
</title>
so on....
Could somebody explain whats the problem here.. Thanks in advance
解决方案
Then you might want to put explicit waits like below:
void waitForLoad(WebDriver driver) { ExpectedCondition pageLoads = new ExpectedCondition() { public Boolean apply(WebDriver driver) { return (Boolean)((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete"); } }; WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(pageLoads); }
And then you can perform below action:
driver.getTitle()
这篇关于Selenium driver.getTitle() 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文