mardi 28 août 2018

Use String in CSS and then select it

Im trying to use a css selector to find an element on a page and then select it. I have the string separate and im trying to add it to the css selector and then select the webelement but non of my code is working. Currently ive tried:

String first_pick_one_points WebElement re_button = Drivers.getDriver().findElement(By.cssSelector("//*[contains(text())=" + first_pick_one_points +"]")); re_button.click();

and also tried

    String re_enter_button = Drivers.getDriver().findElement(By.xpath("data-qa-pick-button-value")).getAttribute(first_pick_one_points);

WebElement button = Drivers.getDriver().findElement(By.xpath(re_enter_button); button.click();

Below is the html snippet from the site

<div class="_1joc06t" data-qa-fixture-id="984393"><div class="_1om3izrp"><button data-qa-selection-button="0" class="_28ra6rl"><p class="_ptbkw3" aria-label="selection_value" data-qa-pick-button-value="">144</p><div class="_we64c1"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><title>disabled</title><path d="M0 0h24v24H0z" fill="none"></path><path fill="#858585" d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z"></path></svg></div></button><span class="_1cm44rd">Win</span></div><div class="_1om3izrp"><button data-qa-selection-button="1" class="_102fot45" disabled=""><p class="_1mx46zzh" aria-label="selection_value" data-qa-pick-button-value="">380</p><div class="_d55d17a"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><title>disabled</title><path d="M0 0h24v24H0z" fill="none"></path><path fill="#858585" d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z"></path></svg></div></button><span class="_1cm44rd">Draw</span></div><div class="_1om3izrp"><button data-qa-selection-button="2" class="_102fot45" disabled=""><p class="_1mx46zzh" aria-label="selection_value" data-qa-pick-button-value="">750</p><div class="_d55d17a"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><title>disabled</title><path d="M0 0h24v24H0z" fill="none"></path><path fill="#858585" d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z"></path></svg></div></button><span class="_1cm44rd">Win</span></div></div>

Aucun commentaire:

Enregistrer un commentaire