使用jython的函数java构造(谓词)
因此,我正试图使用jython提供的selenium java库是的,我知道selenium有一个python接口,但是出于公司团队合作的考虑,如果能够很好地使用纯java库,那么访问它会更有意义 我只是尝试在这里执行示例脚本: 我已经用以下jython代码实现了:使用jython的函数java构造(谓词),java,python,jython,selenium-webdriver,Java,Python,Jython,Selenium Webdriver,因此,我正试图使用jython提供的selenium java库是的,我知道selenium有一个python接口,但是出于公司团队合作的考虑,如果能够很好地使用纯java库,那么访问它会更有意义 我只是尝试在这里执行示例脚本: 我已经用以下jython代码实现了: from org.openqa.selenium.firefox import FirefoxDriver from org.openqa.selenium import By from org.openqa.selenium im
from org.openqa.selenium.firefox import FirefoxDriver
from org.openqa.selenium import By
from org.openqa.selenium import WebDriver
from org.openqa.selenium import WebElement
from org.openqa.selenium.support.ui import ExpectedCondition
from org.openqa.selenium.support.ui import WebDriverWait
driver = FirefoxDriver()
driver.get('http://www.google.com')
element = driver.findElement(By.name('q'))
# The array wrapper around the string is the only weird thing I encountered
element.sendKeys(["Cheese!"])
print "Page title is: " + driver.getTitle()
class ExpectedConditionTitle(ExpectedCondition):
def apply(d):
print(type(d))
return d.title.toLowerCase().startsWith(["cheese!"])
def equals(d):
pass
print(type(driver))
WebDriverWait(driver, 10).until(ExpectedConditionTitle().apply())
print driver.getTitle()
driver.quit()
而且它在按预期的条件吐。我不知道如何为until所希望的种类创建子类。我的代码中出现了以下错误:
最后的
回溯最里面的最后一个:
文件Example.py,第24行,在?
应用中第19行的Example.py文件
AttributeError:“实例”对象没有属性“标题”
和
回溯最里面的最后一个:
文件Example.py,第24行,在?
应用中第19行的Example.py文件
AttributeError:getTitle
和
回溯最里面的最后一个:
文件Example.py,第22行,在?
TypeError:until:1st参数不能强制为com.google.common.base.Function或com.google.common.base.Predicate
硒基本上只是人类的一个幌子
我对python或java不够精通,无法理解这一点。有人知道我该如何实现这一点吗?因此,我通过以下操作使它能够识别谓词函数:def applyd,I:它能够识别ExpectedCondition title并正确地将驱动程序传递给它。老实说,我不知道第二个论点是什么。现在我可以得到它了,但它返回的是python字符串,而不是java字符串,所以我不能使用小写和startsWith。我试着用函数创建自己的start,并像这样包装它return startsWithi.getTitle.lower,cheese!,但现在我得到了一个命名错误:错误的错误…我也发现了。我需要得到jython 2.5,我得到了jython 2.2,它实际上没有布尔类。通过返回0表示true,返回1表示false,它基本上是有效的。现在它很奇怪,因为它存在循环,不管我把零和一放在哪里,这意味着它只是在第一次通过时返回。该死