4

How can I select "Fiyata göre Artan"?

<div class="search-top hidden-xs">
<div class="destination-info hidden-xs">
<div class="search-sort dropdown open"><div class="pseudo-border-bottom hidden-xs">
</div><div id="result-sort-box" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<ul id="sort-list" class="dropdown-menu dropdown-menu-sort sort-list" aria-labelledby="result-sort-box">
<li data-sort-theme="plh">Fiyata göre artan</li>
<li data-sort-theme="phl">Fiyata göre azalan</li>
<li class="active" data-sort-theme="ms">İlgiye göre</li></ul></div></div>

I tried with XPath but I'm getting an error:

org.openqa.selenium.ElementNotVisibleException: element not visible

My full work is here https://paste.ubuntu.com/24954431/

enter image description here

3 Answers 3

2

You can select the element by text using an XPath expression:

driver.findElement(By.xpath("//ul[@id='sort-list']//li[. = 'Fiyata göre artan']")).click();

Make sure to open up the dropdown before clicking the dropdown element.

1

You need to click on whatever makes your element visible first.

Selenium by design cannot do anything the user cannot do, like clicking on an element which is not visible or enabled.

So not being able here is not a bug, it is a feature. It prevents you from making page interactions in Selenium which user cannot do (detects impossible interactions).

0

After many try , i solved my problem with using hover action and JavascriptExecutor.

    Actions builder = new Actions(driver);
    WebElement fiyataGore = driver.findElement(By.cssSelector("#sort-list > li:nth-child(1)"));
    WebElement ilgiyeGore = driver.findElement(By.cssSelector("#sort-list > li.active"));
    ((JavascriptExecutor) driver).executeScript("arguments[0].className='active'",fiyataGore);
    ((JavascriptExecutor) driver).executeScript("arguments[0].className=''",ilgiyeGore);
    ((JavascriptExecutor)driver).executeScript("arguments[0].click();", fiyataGore);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.