Used: c # , webdriver , selenium .

SCENARIO

  1. CODE. Opens Chrome Browser
  2. PERSON. Opens three tabs
    • Tab 1 - Site 1;
    • Tab 2 - Site 2;
    • Tab 3 - Site 3;
  3. PERSON. Moves (activates) to Tab 2;

QUESTION

  1. How do you click on button1 to output the URL of Site 2 to labe1?
  • It seems to be nothing. You can get the current URL of the tabs, on which the selenium is located, but the fact that the person will scroll through the tabs will not be recognized by the selenium. - Andrew Bystrov

1 answer 1

In the button click handler add:

driver.SwitchTo().Window(driver.WindowHandles[1]); // переключаем драйвер на 2 вкладку label1.Text = driver.Url; // получаем текущий URL активной вкладки 

Either way:

 label1.Text = driver.SwitchTo().Window(driver.WindowHandles[1]).Url; 
  • As I understand it, he needs to know the tab to which the person switched manually. Those. This code will not work if a person chose 3, 4.5, .... 100 tab - Andrew Bystrov
  • @AndrewBystrov is not aware, there is no such information in the question, I wrote a specific solution to the specific question "How do I click on the button1 to display the URL of Site 2 in labe1?" - tCode
  • Well, how not. He described in steps what the person did and after that the url should be removed from the site2, since Man has moved on her. Or am I wrong? - Andrew Bystrov
  • The essence is clear. I correctly understood that this code is only accessing the tab, but in fact it turns out not "pressed"? Those. If we consider the following scenario: 1. CODE. Opens Chrome Browser 2. PERSON. Opens three tabs Tab 1 - Site 1; Tab 2 - Site 2; Tab 3 - Site 3; 3. MAN. Presses a button. button1. The necessary data for the next item (p.4) will be taken from TextBox 4. CODE. Moves (activates) to Tab 2; QUESTION (VAR. 2) How do I click on button1 to display the URL of Site 2 in labe1? - koverflow