0

Hello I want you to get the text @user i.e. ( span class="user" ) from Class messenger using driver.FindElementsByCssSelector('');

Because the same code is on the same page, but with a different start div class="messenger"

Note: The code cannot be changed on the site

<div class="messenger">
    <div class="two"> 
        <div class="three">  
            <a class="complex" rel="user" href="https://example.com"> 
                <img class="avatar pull-right" src="https://example.co/a.jpg" alt="avatar"> 
            </a>    
        </div> 
        <div class="webs">      
            <a class="link-complex" rel="user" href="afaq"> 
                <b class="link-complex-target">website</b> 
                <span class="user">@user</span> 
            </a>
        </div>
    </div> 
</div>
dbc
  • 104,963
  • 20
  • 228
  • 340

1 Answers1

0

To extract the text @user so you have to induce WebDriverWait for the desired ElementToBeClickable() and you can use either of the following Locator Strategies:

  • ClassName:

    Console.WriteLine(new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementIsVisible(By.ClassName("user"))).Text);
    
  • CssSelector:

    Console.WriteLine(new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementIsVisible(By.XPath("//span.user"))).GetAttribute("value"));
    
  • XPath:

    Console.WriteLine(new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementIsVisible(By.XPath("//span[@class='user']"))).GetAttribute("value"));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352