Нужно что бы открывало ссылку на видео на сайте youtube.com перепробовал уже и xpath и Linktext и selector ничего не срабатывает вот код
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.Select;
import com.sun.org.apache.xerces.internal.impl.xs.identity.Selector;
public class googleTest1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\chrome\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.addArguments("--disable-notifications");
WebDriver driver = new ChromeDriver();
//go to google.com
driver.get("http://www.google.com");
//maximize chrome window
driver.manage().window().maximize();
//google search
driver.findElement(By.xpath("//input[@name=\"q\"]")).sendKeys("youtube");
//click on button
driver.findElement(By.xpath("//*[@id=\"tsf\"]/div[2]/div[1]/div[3]/center/input[1]")).sendKeys(Keys.ENTER);
//click on link "youtube"
driver.findElement(By.className("S3Uucc")).click();
//search field on youtube.com
driver.findElement(By.id("search")).sendKeys("Linkin Park - Numb");
//click on button search
driver.findElement(By.id("search-icon-legacy")).sendKeys(Keys.ENTER);
//press on link video
driver.findElement(By.l("Numb (Official Video) - Linkin Park")).sendKeys(Keys.ENTER);
}
}
Попробуй так:
//click on link video
WebElement lpVideo = driver.findElement(By.xpath("путь к видео"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", lpVideo);
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости