1

I am making script that will login to "https://asia.nikkei.com/". The script opens the login window which is in a iframe.

But then iam not able to select <inputs> for email and password. And when I try to switchTo iframe with id "piano-id-AciFE", I'm getting "no such frame" error using this code:

$driver->switchTo()->frame("piano-id-AciFE");

I tried another solution with:

$username = $driver->switchTo()->activeElement();

after the login window open, but this solution doesnt work either.

Is there any way to select login input in this case?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

The value of the id attribute is partially static (i.e. piano-id-) and partially dynamic (i.e. AciFE). When I access the website I find the value of the id attribute as piano-id-IE9ZK

In such cases to switch to the desired iframe you can refer to the preceeding(sibling) WebElement and you can use the following locator strategy:

  • Using xpath and following:

    $element = $driver->findElement(WebDriverBy::xpath("//button[@aria-label='Close']//following::iframe[1]"));
    $driver->switchTo()->frame(element);
    
  • Using xpath and following-sibling:

    $element = $driver->findElement(WebDriverBy::xpath("//button[@aria-label='Close']//following-sibling::iframe[1]"));
    $driver->switchTo()->frame(element);
    

You can find a relevant detailed discussion in WebDriver - How to locate iframe without id

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352