網站網址。https://staging.corporatehousingbyowner.com/
嗨。 我無法通過Java的Selenium Webdriver找到并點擊UL > li中的以下按鈕。 使用Chrome驅動程式來執行自動執行。
<ul>
<li><a class="list-your-prop" href="/dashboard/properties/add/"> List Your Property</a> </li>
<ul/>
已經嘗試了下列解決方案。
1:
WebElement element = driver. findElement(By.linkText("List Your Property")) 。
element.click()。
2:
WebElement element = driver.findElement(By.className("menu-text"))。
String elementText = element.getText()。
3:
WebElement element = driver. findElement(By.xpath("//li[contains(@class,'list-your-prop')]/ul/li/a"))。)
element.click()。
4: driver.findElement(By.cssSelector("body > header:nth-child(1) > nav:nth-child(4) > div:nth-child(1) > div:nth-child(2) > ul:nth-child(2) > li:nth-child(4) > a:nth-child(1)").click(); /code>
[網頁亮點][1]。 [1]: https://i.stack.imgur.com/FH2LR.png
請幫助,預先感謝。
uj5u.com熱心網友回復:
有兩個網頁元素有List Your Property。
下面的xpath在HTMLDOM
//div[@id='myNavbar']/descendant::a[text()='List Your Property']/span>
代碼試用1 :
WebElement element = driver. findElement(By.xpath("//div[@id='myNavbar']/descendant::a[text()='List Your Property']")。
element.click()。
代碼試用2 : 使用明確的等待:
WebElement element = new WebDriverWait(driver, 持續時間。 ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@id='myNavbar']/descendant::a[text()='List Your Property']"/span>)。
element.click()。
Update 1 :
driver.manage().window().maximum()。
//WebDriverWait wait = new WebDriverWait(driver, 30);
//driver.manage().timeouts().implicitlyWait(300, TimeUnit.SECONDS);
driver.get("https://staging.corporatehousingbyowner.com/");
WebElement element = new WebDriverWait(driver, 20)。) until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@id='myNavbar']/descendant::a[text()='List Your Property']") )。
element.click()。
uj5u.com熱心網友回復:
你可以使用
driver.findElement(By.cssSelector("nav.navbar a.list-your-prop")).click();
使用等待者也比較好,因為該元素可能需要時間來加載。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/309770.html
標籤:
