夥計們,請你幫幫我。Selenium從下拉列表中找到xpath建議
我需要找到的XPath爲iPhone 6S(當我鍵入searchfield 'iphone' 的建議給出)
這不起作用:
Actions actions = new Actions (driver);
actions.moveToElement(searchField).perform();
driver.findElement(By.linkText("iphone 6s")).click();
夥計們,請你幫幫我。Selenium從下拉列表中找到xpath建議
我需要找到的XPath爲iPhone 6S(當我鍵入searchfield 'iphone' 的建議給出)
這不起作用:
Actions actions = new Actions (driver);
actions.moveToElement(searchField).perform();
driver.findElement(By.linkText("iphone 6s")).click();
嘗試執行以下操作:
Actions actions = new Actions (driver);
WebElement inputField = driver.findElement(By.xpath("//input[@type='text']"));
actions.moveToElement(inputField).sendKeys("iphone 6s")
.moveToElement(driver.findElement(By.xpath("//a[span[text()=' 6s']]")))
.click()
.build()
.perform();
CSS選擇器"a[data-query='iphone 6s']"
應該工作。
driver.findElement(By.cssSelector("a[data-query='iphone 6s']")).click();
不起作用。no such element:Unable to locate element :{「method」:「css selector」,「selector」:「a [data-query ='iphone 6s']」} – Aksana
您需要添加一個服務員的建議出現,您不能使用By.linkText
,因爲結果並不<a>
標籤。
這裏是工作示例(JAVA)的網站:
By searchInput = By.cssSelector("#gh-search-input");
By suggestionIPhone = By.cssSelector("ul.suggestion-list li[title='iphone 6s']");
driver.findElement(searchInput).sendKeys("iphone 6s");
new WebDriverWait(driver, 15)
.until(ExpectedConditions.presenceOfElementLocated(suggestionIPhone))
.click();
鏈接文本不是「iPhone 6S」嘗試全文或使用數據查詢屬性? – user993553
'Byxxpath(「// * [contains(text(),'iphone 6s'))]''? – JDelorean
我試過了。沒有工作 – Aksana