I tried everything to make my code click the button but it can't. I tried using xpath, id, class. Neither of them worked. Does anyone have an idea for this to work?
HTML:
<div data-focus-lock-disabled="false" class="inner-1ilYF7">
<form class="modal-yWgWj- container-14fypd sizeSmall-1jtLQy fullscreenOnMobile-1aglG_">
<div class="scrollerWrap-2lJEkd content-1EtbQh scrollerThemed-2oenus themeGhostHairline-DBD-2d">
<div class="scroller-2FKFPG systemPad-3UxEGl inner-ZyuQk0 content-dfabe7">
<h2 class="h2-2gWE-o title-3sZWYQ defaultColor-1_ajX0 title-18-Ds0 marginBottom20-32qID7 marginTop8-1DLZ1n">WOAH THERE. WAY TOO SPICY</h2>
<div class="body-Mj9Oxz medium-zmzTW- primary-jw0I4K">You're sending messages too quickly!</div>
</div>
</div>
<div class="flex-1xMQg5 flex-1O1GKY horizontalReverse-2eTKWD horizontalReverse-3tRjY7 flex-1O1GKY directionRowReverse-m8IjIq justifyBetween-2tTqYu alignStretch-DpGPf3 wrap-ZIn9Iy footer-3rDWdC" style="flex: 0 0 auto;">
<button type="submit" class="primaryButton-2BsGPp button-38aScr lookFilled-1Gx00P colorBrand-3pXr91 sizeXlarge-2yFAlZ grow-q77ONN">
<div class="contents-18-Yxp">Enter the chill zone</div>
</button>
</div>
</form>
</div>
My code for finding the button looks like this:
try
{
var element = driver.FindElement(By.XPath("//*[text()='Enter the chill zone']"));
if (element.Displayed)
{
driver.FindElement(By.XPath("/html/body/div/div[2]/div[2]/div[2]/div[3]/form/div[2]/button")).Click();
Console.WriteLine("Button clicked!");
}
}
catch (Exception e)
{
Console.WriteLine(e);
}