Advertisement
SeleniumETrainR

How to automate youtube using selenium Webdriver?

Dec 3rd, 2012
2,604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. import org.openqa.selenium.JavascriptExecutor;
  2. import org.openqa.selenium.WebDriver;
  3.  
  4.  
  5. public class FlashObjectWebDriver {
  6. private final WebDriver webDriver;
  7. private final String flashObjectId;
  8.  
  9. public FlashObjectWebDriver(final WebDriver webDriver, final String flashObjectId) {
  10. this.webDriver = webDriver;
  11. this.flashObjectId = flashObjectId;
  12. }
  13.  
  14. public String click(final String objectId, final String optionalButtonLabel) {
  15. return callFlashObject("doFlexClick", objectId, optionalButtonLabel);
  16. }
  17.  
  18. public String click(final String objectId) {
  19. return click(objectId, "");
  20. }
  21.  
  22.  
  23.  
  24. public String callFlashObject(final String functionName, final String... args) {
  25. final Object result =
  26. ((JavascriptExecutor)webDriver).executeScript(
  27. makeJsFunction(functionName, args),
  28. new Object[0]);
  29.  
  30. return result != null ? result.toString() : null;
  31. }
  32.  
  33. private String makeJsFunction(final String functionName, final String... args) {
  34. final StringBuffer functionArgs = new StringBuffer();
  35.  
  36. if (args.length > 0) {
  37. for (int i = 0; i < args.length; i++) {
  38. if (i > 0) {
  39. functionArgs.append(",");
  40. }
  41. functionArgs.append(String.format("'%1$s'", args[i]));
  42. }
  43. }
  44. return String.format(
  45. "return document.%1$s.%2$s(%3$s);",
  46. flashObjectId,
  47. functionName,
  48. functionArgs);
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement