2

I want to click on element which appears like a button on webpage using style attribute of div tag.

But I am not able to do so. I referred stack overflow but with the help of that its returning blank element . I don't want any text. I want that it should be clicked and the list appears and I want to select one item from that list. So how to do that?

Below is my code :

<div style="width: auto; height: 386px;" class="QvGraph">
<img src=" " style="width: 710px; height: 386px; cursor: crosshair; visibility: visible; display: block;"></img>
<div style="cursor: pointer; position: absolute; top: 4px; left: 588px; height: 18px; width: 27px;" class="Qv_Hotspot"></div>
<div style="cursor: pointer; position: absolute; top: 3px; left: 3px; height: 18px; width: 18px;" class="Qv_Hotspot"></div></div>
</div>  

I have tried this below code, but it didn't get work for me.

driver.findElement(By.xpath("//div[@class ='Qv_HotSpot']")).getAttribute("cursor: pointer; position: absolute; top: 4px; left: 588px; height: 18px; width: 27px;");  

I am badly stuck here .Thanks in advance !

1 Answer 1

3

Try this below code.

If you want to click on <div> tag style attribute use below code.

driver.findElement(By.xpath("//div[@class='Qv_Hotspot'][@style='cursor: pointer; position: absolute; top: 4px; left: 588px; height: 18px; width: 27px;']")).click();

Explanation of xpath:- Use class and style attribute of <div> tag.

Sign up to request clarification or add additional context in comments.

9 Comments

Thank you @jainish but it clicks on the image which I don't want. I want to click on the other div below image. I edited your code but it doesn't work driver.findElement(By .xpath("//div[@class='Qv_HotSpot']/div[@style='cursor: pointer; position: absolute; top: 4px; left: 588px; height: 18px; width: 27px']")) .click();
Now is it for you as you expected? Can you explain me why you were modifying my xpath? Please replace my code with your code. Then only it gets work for you.
It will stop the execution of your code for 5 mils-seconds. Usually this will help when your code is interacting with ajax or when you click on button then re-load the page, that time this will work better.
You mean that it will load data first and then it will execute the below code ? then why it isn't needed in the case of other statements ?
Yes, First load the data and then after your driver will able to find the web-element. You should use this statement when your web-element may interrupt by loading.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.