The task is press button "More" in https://play.google.com/store/apps/category/FINANCE/collection/topselling_paid
This is screenshot
http://c2n.me/i9LC1O
My code is:
String url = "https://play.google.com/store/apps/category/FINANCE/collection/topselling_paid";
WebDriver driver = new HtmlUnitDriver();
driver.manage().timeouts().implicitlyWait(100000, TimeUnit.SECONDS);
driver.get(url);
//Collects ONLY first 60 link. `enter code here`But I need more....
ArrayList<WebElement> linksToApp = (ArrayList<WebElement>) driver
.findElements((By.className("title")));
ArrayList<String> urlToApp = new ArrayList<String>();
Please, help me.
You need to do something like
driver.findElement(By.id("id-of-show_more-button")).click();
You can find the element id byt right clicking on the element, click on inspect element and then checking for the id attribute in the HTML
Related
New to automation and could use some help here.
I am using Selenium Webdriver and Java on this website - Webdriver University and so far this code has been throwing No Such Element exception at "element.click()" step (i.e., doesn't find the element on page):
driver.manage().window().maximize();
driver.get("http://webdriveruniversity.com");
Thread.sleep(3000);
// Follow the link to another page
WebElement link = driver.findElementByXPath("(//div[#class=\"section-title\"])[6]");
link.click();
Thread.sleep(3000);
// Click on the element
WebElement element = driver.findElementByXPath("(//button[#class='accordion'])[1]");
element.click();
However, when I go to the linked page directly, it finds the element just fine
driver.manage().window().maximize();
driver.get("http://webdriveruniversity.com/Accordion/index.html");
// Click on the element
WebElement element = driver.findElementByXPath("(//button[#class='accordion'])[1]");
element.click();
I've used wait for element visibility and Thread sleeps, same results.
Any idea what could be the issue here?
Did you notice that when you click the link, page is opened in new tab? That is your issue.
You need to switch to new tab.
ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(tabs.get(1)); //here you are switch to second tab
Hope the below code will solve your issues.
Used the getWindowHandles() to capture handle of newly opened tab and switch to the
tab
// Follow the link to another page
WebElement link = driver.findElement(By.xpath("(//div[#class=\"section-title\"][6]"));
link.click();
Set<String> allWindow = driver.getWindowHandles();
Iterator<String> itr = allWindow.iterator();
while (itr.hasNext()) {
String wind = itr.next().toString();
driver.switchTo().window(wind);
}
Thread.sleep(3000);
// Click on the element
WebElement element = driver.findElement(By.xpath("(//button[#class='accordion'][1]"));
element.click();
Thread.sleep(3000);
driver.close();
}
url = http://www.yopmail.com/en/
public class ReadEmailForEmailChange {
WebDriver drive = new FirefoxDriver();
drive.get("http://www.yopmail.com/en/");
// I am able to get the size of frms
int size = drive.findElements(By.tagName("iframe")).size();
// this is the user name send keys.
WebElement emai = (WebElement) drive.findElement(By.xpath("//input[#id='login']"));
emai.sendKeys("testdenmark");
// this is button to click. it is working as well
WebElement emaenter = (WebElement)drive.findElement(By.xpath("//input[#title='Check inbox #yopmail.com']"));
emaenter.click();
// this is 1st frame. i am able to switch to this frame with no prob
drive.switchTo().frame(drive.findElement(By.id("ifinbox")));
// this is to find the email based on subject text. it is working fine
WebElement emailopen = (WebElement) drive.findElement(By.xpath("//span[#class='lms' and text()='email verification']"));
emailopen.click();
System.out.println("got to the emial.");
// here comes problem. i am 100% that Id is correct or xpath is correct
but i am not able to switch to this frame. I am getting element not found except
//WebElement frame = drive.findElement(By.xpath("//tr//td//iframe[#id='ifmail']"));
//drive.switchTo().frame(drive.findElement(By.id("ifmail")));
//drive.switchTo().frame(drive.findElement(By.xpath("//iframe[#id='ifmail']")));
this will happen after i switch to the frame
drive.findElement(By.xpath("//a[text()='Verify email']")).click();
The iframe is
<iframe class="whc" frameborder="0" scrolling="auto" id="ifmail" name="ifmail" src=""></iframe>
Sounds like you need to wait for the iframe to appear first. Try a webdriver wait before attempting to switch to the IFrame.
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ifmail")));
Below is the code
WebDriver dr= new ChromeDriver();
dr.get("http://obsessory.com/");
dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[1]/a")).click();
dr.findElement(By.id("email")).sendKeys("username#gmail.com");
dr.findElement(By.name("LoginForm[password]")).sendKeys("password");
dr.findElement(By.xpath(".//[#id='signIn']/div[2]/div[3]/div[3]/input")).click();
Actions action = new Actions(dr);
WebElement we = dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/a/span"));
action.moveToElement(we).moveToElement(dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/ul/li[1]/a"))).click().build().perform();
I wanted to click on 'my accounts' or any of those other links. Kindle tell me how to do that
#kavya
Please try this code. I think you are not able to type password in password textbox.
For password:
dr.findElement(By.xpath("(//input[#id='email'])[2]")).sendKeys("obsessory");
For Menu:
WebElement we = dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/a"));
WebElement ve = dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/ul/li[1]/a"));
Actions act = new Actions(dr);
act.moveToElement(we).click(ve).perform();
Hope this will work
Try with
Actions action= new Actions(dr);
WebElement we = dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/a/span"));
action.moveToElement(we).perform();
By locator = By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/ul/li[1]/a");
dr.click(locator);
Not able to Select the month for Date of Birth.
Code I am using is:
driver.findElement(By.xpath(".//*[#id = 'BirthMonth']/div")).click();
Thread.sleep(3000);
WebElement months = driver.findElement(By.xpath(".//[#id='BirthMonth']/div[2]/div[#id=':1']"));
Thread.sleep(2000);
months.click();
I also tried with by using DropDownList case. But Not able to set any Month.
Please Say me the Solution.
You can use keyboard event replace mouse.
WebElement birthMonth = driver.findElement(By.id("BirthMonth"));
birthMonth.click();
Actions action = new Actions(driver);
action.sendKeys(Keys.DOWN).sendKeys(Keys.ENTER).perform();
We can use sendKeys directly:
driver.findElement(By.xpath(".//*[#id='BirthMonth']/div[1]")).sendKeys("July");
You can wrap this up in a function
public void selectBirthMonth(int monthIndex)
{
driver.findElement(By.cssSelector("#BirthMonth > div")).click();
driver.findElements(By.cssSelector("#BirthMonth > div.goog-menu > div.goog-menuitem")).get(monthIndex - 1).click();
}
and then call it like
selectBirthMonth(9); // 1 = January
WebElement month = wd.findElement(By.xpath("//[#id=\"BirthMonth\"]/div[1]"));
month.click();
Thread.sleep(3000);
//wd.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//fetch months from the dropdown and store it in a list
List<WebElement> month_dropdown = wd.findElements(By.xpath("//[#id=\"BirthMonth\"]/div[2]/div/div"));
//iterate the list and get the expected month
for (WebElement month_ele:month_dropdown){
String expected_month = month_ele.getAttribute("innerHTML");
// Break the loop if match found
if(expected_month.equalsIgnoreCase("August")){
month_ele.click();
break;
}
}
It is not drop down value , you have to click on drop down arrows and then click on any value which you have to pass from script.
Code is below:
System.setProperty("webdriver.chrome.driver", "E:/software and tools/chromedriver_win32/chromedriver.exe");
WebDriver driver= new ChromeDriver();
//FirefoxDriver driver= new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://accounts.google.com/SignUp");
Thread.sleep(5000);
driver.findElement(By.xpath(".//*[#id='BirthMonth']/div[1]/div[2]")).click();
driver.findElement(By.xpath(".//*[#id=':7']/div")).click();
it is workable code for Birthmonth
Please find below link for same type of Question
Not able to select the value from drop down list by using Select method in Selenium
I've just begun using selenium web-driver. I'm trying to use it login and navigate/scrape.
public static void main(String[] args) {
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF);
java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF);
WebDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME);
driver.get("my_Site_I_Reference");
#SuppressWarnings("unused")
WebDriverWait wait = new WebDriverWait(driver, 4000);
WebElement name = driver.findElement(By.id("LoginUsername"));
name.sendKeys("exampleName");
name.submit();
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
I'm using the code above to try and enter a username into the username field but I am constantly met with this error:
"org.openqa.selenium.NoSuchElementException: Unable to locate element with ID: LoginUsername"
I'm almost certain the element is called LoginUsername as shown in the picture:
Any help would be very much appreciated, thanks!
It would be still a guess, but I suspect the element is inside an iframe. If this is the case, switch to the iframe before looking for the element:
driver.switchTo().frame("frame_id_or_name");
WebElement name = driver.findElement(By.id("LoginUsername"));
Can you please share HTML code in detail ? Meanwhile, You can also give a try by changing it to below and share what do you see?
WebElement name = driver.findElement(By.xpath(“//*[#id="LoginUsername"]”));
OR
WebElement name = driver.findElement(By.xpath(“//input[#id="LoginUsername"]”));
Turns out that I had Javascript disabled by default I found this out by printing the page source my code loaded
((HtmlUnitDriver) driver).setJavascriptEnabled(true);
Once enabled selenium behaved like I expected