0

I have a div and within it several debts. In each div, I have a title, results and a final div to click on. How do I make the click event in this final div according to a title search?

I have experience with WebDriver and PHP, but I've tried it all with the function By.xpath but no success.

Example: I need to click in <div class="Link_Text "></div> if it has the text "Race 19 Magic" in the <div classe="RaceTitle "></div>

How to?

$driver->findElement(By.xpath(" XPATH_HERE "))->click();

<div>
    <div class="races ">
        <div class="FixedRace ">
            <div class="RaceTitle ">Race 19 Magic</div>
            <div class="Link ">
                <div class="Link_Text ">See All</div>
            </div>
        </div>
        <div class="FixedRace ">
            <div class="RaceTitle ">8.57 Mega (Race 10)</div>
            <div class="Link ">
                <div class="Link_Text ">See All</div>
            </div>
        </div>
    </div>
</div>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Senror Gui
  • 80
  • 9
  • where are the event handlers? Basically you can check the text in xpath by using .text()... something like "//*[contains(text(), "your_text")] Exactly what you need to click on is unclear though. Does a script set event handlers to the divs? – pcalkins Oct 30 '19 at 22:23
  • @pcalkins Exactly. Find the main div that contains the text "Race 19 Magic", isolate this div and click on its respective div Link_Text – Senror Gui Oct 30 '19 at 22:43

2 Answers2

0

I have found the following customized xpath as per your Example. Please let me know either it is working or not?

driver.findElement(By.xpath("//div[text()='See All']//parent::div[@class='Link ']//preceding-sibling::div[text()='Race 19 Magic']")).click();
khawar
  • 112
  • 1
  • 5
0

To click the <div> with text as See All with respect to the <div> with text as Race 19 Magic you can use the following Locator Strategy:

  • XPath 1:

    $driver->findElement(By.xpath("//div[@class='RaceTitle ' and text()='Race 19 Magic']//following::div[1]/div[@class='Link_Text ' and text()='See All']"))->click();
    
  • XPath 2:

    $driver->findElement(By.xpath("//div[@class='RaceTitle ' and contains(., 'Race 19 Magic')]//following::div[1]/div[@class='Link_Text ' and text()='See All']"))->click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352