Selenium 如何在网页上单击带有href属性的按钮

Selenium 如何在网页上单击带有href属性的按钮,selenium,webdriver,Selenium,Webdriver,我使用以下代码单击登录按钮,但它不起作用: 试验1: driver.findElement(By.xpath("//a[text()='https://www.luxproflashlights.com/customer/account/login/referer/aHR0cHM6Ly93d3cubHV4cHJvZmxhc2hsaWdodHMuY29tLw%2C%2C/']")).click(); 试验2: driver.findElement(By.linkText("Log In")).

我使用以下代码单击登录按钮,但它不起作用:

试验1:

driver.findElement(By.xpath("//a[text()='https://www.luxproflashlights.com/customer/account/login/referer/aHR0cHM6Ly93d3cubHV4cHJvZmxhc2hsaWdodHMuY29tLw%2C%2C/']")).click(); 
试验2:

driver.findElement(By.linkText("Log In")).click();

如果元素同时包含href属性和文本登录,则可以使用以下任一选项:

PartialLink文本:

xpath:


可能应该是//a[href='…']或//a[contains@href,“login']文本用于之间的内容。
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.partialLinkText("Log In"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(@href, 'luxproflashlights') and contains(., 'Log In')]"))).click();