Home > Net >  select text from span in selenium java enviroment , when its not a drop box
select text from span in selenium java enviroment , when its not a drop box

Time:07-01

so I want to select the text of span in selenium java, as it is not a normal drop-down box, I would have done it easily, I am using XPath I am able to open that drop-down box (where we select different sizes of shirt) type but no able to select text from it, I am sharing website link and also sharing my code https://www.ounass.ae/shop-emporio-armani-camouflage-print-t-shirt-in-mercerised-cotton-for-men-215380566_20.html

my Code,

package First_Test;

import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WindowType;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ISelect;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.Keys;

import io.github.bonigarcia.wdm.WebDriverManager;

    public class Practice_First {
        
        public static void main(String[] args) throws InterruptedException {
            
            //System.setProperty("webdriver.chrome.driver", "./Driver/chromedriver.exe");
    
            WebDriverManager.chromedriver().setup();
            
            
            WebDriver driver = new ChromeDriver();
            
            driver.get("https://www.ounass.ae/");
    
            driver.manage().window().maximize();
    
            Thread.sleep(3000);
    
                         String originalWindow= driver.getWindowHandle();
    
                     Thread.sleep(5000);
        
                       driver.findElement(By.id("wzrk-cancel")).click();      
                       
                 // driver.findElement(By.xpath("//button[@id='wzrk-cancel']")).click();
                  driver.findElement(By.xpath("//a[@href='/men']//div[@class='Gender-centralize']//span[@class='Gender-CTA'][normalize-space()='Shop Now']")).click();
    
                  Thread.sleep(2000);
                 //driver.findElement(By.cssSelector("a[href='shop-emporio-armani-camouflage-print-t-shirt-in-mercerised-cotton-for-men-215380566_20.html']")).click();
                  // driver.findElement(By.cssSelector("a[title=\"Camouflage Print T-shirt in Mercerised Cotton\"]")).click();
                  
                  driver.findElement(By.xpath("//span[normalize-space()='675 AED']")).click();
    
                  Thread.sleep(3000);
    
                 driver.findElement(By.xpath("//button[@title='Blue']")).click();
    
                 Thread.sleep(2000);
                 
               driver.findElement(By.xpath("//div[@class='Select-control']")).click();
    
               Thread.sleep(1000);
    
               //driver.findElement(By.xpath("//div[@class='Select Dropdown SizeSelection-options 
             
                Thread.sleep(1000); */      
            //driver.close();
                
        }   
    }

My html code :

<div  xpath="1">
    
    <input name="sizeCode" type="hidden" value="75">
    
    <div >
    
    <div  id="react-select-sizeCode--value">
    
    <div >
    <span  role="option" aria-selected="true" id="react-select-sizeCode--value-item">M</span>
    </div>
    
    <div aria-expanded="false" aria-owns="" aria-activedescendant="react-select-sizeCode--value" aria-disabled="false"  role="combobox" style="border:0;width:1px;display:inline-block" tabindex="0">
    </div>
    
    </div>

    <span ><svg width="12" height="7" viewBox="0 0 20 10" >
    
    <path d="M0 0l10 10L20 0" stroke="#2d2d2d" >
    </path>
    
    
</svg>
    
    

</span>
    
    

</div>
    
   

 </div>

CodePudding user response:

Try below xPath for clicking on dropdown Item.

driver.FindElement(By.Xpath("//*[text()='XS']").Click();
  • Related